April 28, 2003 at 3:32 pm
I have a question concerning datetime sorting.
I have a database with 3 columnns - ID, userid and datetime.
UserID is the ID of a user (duh), and datetime is the date and time that that userid logged on or logged of. A user can log on or off many times in a day.
What I'm looking to do is to extract the earliest and latest time associated with each userid per day.
Can anyone help?
Cheers
Andy
April 28, 2003 at 3:42 pm
Try something like this:
select userid, max([datetime]), min([datetime]) from test group by userid
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
April 28, 2003 at 3:45 pm
If you want it for each day then you try something like this.
select userid, max([datetime]), min([datetime]) from test group by userid, convert(char(10),[datetime])
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
April 28, 2003 at 4:38 pm
An article which maybe of interest to you about "The Call-Costs Problem".
Title: Counting the Costs
URL: http://www.sqlmag.com/Articles/Index.cfm?ArticleID=27592
April 28, 2003 at 4:41 pm
cheers mate, that hit the spot!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply