Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 interview questions

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2009-06-23 : 20:54:18
select * from tbl_Logs
id LogName LogDate
1 out20061106_1.rar 2008-03-09
2 in20061201_1.rar 2008-04-07
3 in20061201_2.rar 2008-04-08
4 in20061201_3.rar 2008-04-08
5 in20061202_1.rar 2008-04-09
6 out20061202_1.rar 2008-04-10


1. Prepare a query that returns a list of unique dates and the total number of logs for each date.
2. Prepare a query that returns the total logs that occurred on the 9th day of any month.

Please help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-23 : 21:13:22
what have you tried ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

eonmantra
Starting Member

11 Posts

Posted - 2009-06-23 : 21:18:06
Well if I am reading the questions correctly...

1.

SELECT LogDate, COUNT(*) AS TotalNumLogs
FROM tbl_Logs
GROUP BY LogDate;

output:

LogDate TotalNumLogs
---------- ------------
2008-03-09 1
2008-04-07 1
2008-04-08 2
2008-04-09 1
2008-04-10 1

(5 row(s) affected)

2.

SELECT COUNT(*) AS TotalLogs
FROM tbl_Logs
WHERE DAY(LogDate) = 9;

output:
TotalLogs
-----------
2

(1 row(s) affected)


Go to Top of Page
   

- Advertisement -