ok..
you got a table name UserLogins with these columns:
LoginTime (type datetime) , Department(type int), LoginID (type varchar (12))
you want to count how many logins for each day for the whole month of January.
I will do them this way:
select convert(char(10),LoginTime,102),count(*) from UserLogins
where LoginTime>="1 Jan 2011" and LoginTime<"1 Feb 2011"
group by convert(char(10),LoginTime,102)
.................................
if you want to group by month for the year 2009, and group them by each departments then you could do:
select convert(char(7),LoginTime,102),Department,count(*) from UserLogins
where LoginTime>="1 Jan 2009" and LoginTime<"1 Jan 2010"
group by convert(char(7),LoginTime,102),Department
Hope you get the idea...
.
0 comments:
Post a Comment