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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Number logged in once a week

Author  Topic 

amreddy
Starting Member

1 Post

Posted - 2007-06-05 : 19:25:15
I have a database which contains user_id that has logintime (which gives logintime everytime a user logs into application)
I am trying to get total number of users that logged in once a week, twice a week, once a day, twice a day.
Can you please help me out in this.
Thanks.
Reddy.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-05 : 19:33:43
once / twice a day

select dateadd(day, datediff(day, 0, logintime), 0), count(*)
from yourtable
group by dateadd(day, datediff(day, 0, logintime), 0)
having count(*) = 1 -- 2 : twice a day


by week

select dateadd(week, datediff(week, 0, logintime), 0), count(*)
from yourtable
group by dateadd(week, datediff(week, 0, logintime), 0)
having count(*) = 1



KH

Go to Top of Page
   

- Advertisement -