Sql query for specific data
I have an Archive Table. The columns are PK, Users and Logdatetime. When Users log in the system i am writing to archive table the user and datetime. A user can login more than one in one day.
The data in Logd开发者_JAVA百科atetime is like '2010-03-16 00:00:00.000'
I need to query all users FIRST Login time in one day and get the user with the datetime like: user1 '2010-03-16 03:21:00.000' user2 '2010-03-16 04:11:00.000'
It does not matter the users order. I tried too many way but couldnt find a way. The only solution i found is the query for all users one by one. But it will take time. Any idea how to do this with a one query or more efficent way?
PS: I am using MS SQL Server 2005
Do you mean that you want the users very first login or the just first of a specific day?
This example query might lead you in the right direction;
SELECT [User], MIN(LogDateTime) AS FirstLogin FROM [Archive Table] GROUP BY [User]
精彩评论