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
 Select Statement For Users

Author  Topic 

Johnph
Posting Yak Master

103 Posts

Posted - 2012-07-19 : 16:36:20
[code]SELECT USER_ID,
,[NAME]
,[USER_LOGIN_TIMESTAMP]
FROM USAGE[/code]

I have a table where I am trying to select the count of USER_LOGIN_TIMESTAMP with all the distinct users.

I want to know each distinct user and the count of the amount of times they loged in (USER_LOGIN_TIMESTAMP)

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-19 : 16:51:26
SELECT USER_ID,[NAME], COUNT(*)
FROM USAGE
GROUP BY USER_ID,[NAME]

If you need a unique number of timestamps (assuming there are duplicates):

SELECT USER_ID,[NAME], COUNT(DISTINCT [USER_LOGIN_TIMESTAMP])
FROM USAGE
GROUP BY USER_ID,[NAME]
Go to Top of Page

Johnph
Posting Yak Master

103 Posts

Posted - 2012-07-19 : 16:57:18
Hey robvolk, thank you.
Go to Top of Page
   

- Advertisement -