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 - 2004-09-15 : 08:23:46
|
| Tony writes "Dear Sirs,I have a table with the following fields:ID integer (can contain duplicates)Log_Date date/timeLog_Time date/timeVal contains values 'H', 'M', 'L'I want to return a count of each possible Val (H, M, L) of the initial entry for each ID.E.g. The table may containID Log_Date Log_Time Val100 12/12/2002 12:50 L100 12/10/2003 11:30 H100 12/12/2004 12:45 M100 12/12/2005 10:45 LThe earliest date/time is 12/12/2002 12:50 and so L = L + 1 for this ID.Want something like:H M L120 50 73Where the numbers are the counts of each H, M, L values for the initial entry only for each ID (possibly group by ID????)Any help would be greatly appreciated.Many Thanks,Tony Leeper" |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-09-15 : 08:50:53
|
| select id, val, count(*) from table1where id = @idvariablegroup by id, valif you want this transformed from cols into rows... then search here for "pivot" |
 |
|
|
|
|
|