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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-21 : 08:08:54
|
| Kashi writes "I'm a log guy. If the status of something is constantly changing, I'd rather use a log to show each time the status changed so that I get the item's change history. But I always face a major dilemma: sorting through that information.Suppose I log each time a person logs into their PC. The log might look something like this:FIELDS:strUsernamedatLoginTimeStampstrComputerstrActivitySAMPLE DATA:jsmith -- 05/18/2001 4:10 PM -- CPU0027 -- LOGGED INjdoe -- 05/18/2001 4:12 PM -- CPU0084 -- LOGGED OUTjsmith -- 05/18/2001 5:15 PM -- CPU0027 -- LOGGED OUTkrucker -- 05/18/2001 6:27 PM -- CPU0015 -- LOGGED INNow, suppose I want to see what everyone's latest status is in a list, for example:jsmith -- 05/18/2001 5:15 PM - CPU0027 -- LOGGED OUTjdoe -- 05/18/2001 4:12 PM -- CPU0084 -- LOGGED OUTkrucker -- 05/18/2001 6:27 PM -- CPU0015 -- LOGGED INIn other words, from a log file with tons of entries for tons of people, I want to see a list that shows each person, the last activity they recorded (logged in, or logged out) and the time of that last activity.I have yet to find this elusive query.This is running in an IIS 5.0 web server through a DSN." |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-04-21 : 08:41:28
|
| select * from mytable ainner join (select strUsername, max(datlogin) from mytable) bon a.strusername = b.strusername and a.datalogin = b.datloginie find the max(last) login for each person....and then find the full record that matches that sub-selection. |
 |
|
|
|
|
|