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 |
MevaD
Starting Member
32 Posts |
Posted - 2013-12-24 : 00:24:51
|
If I have a table like this:ID User Date20 22 1-1-201321 22 1-1-201322 31 1-1-201323 22 1-1-201324 22 1-2-201325 22 1-2-2013etc...How can I get the count of records grouped by date and user?Date 22 311-1-2013 3 11-2-2013 2 0etc...Is this possible?Thanks. |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-12-24 : 00:56:46
|
SELECT *FROM (SELECT [User], DATE, Id FROM TableName) pvtPIVOT (COUNT(id) FOR [User] IN ([22], [31]))p--Chandu |
 |
|
MevaD
Starting Member
32 Posts |
Posted - 2013-12-24 : 01:11:41
|
Thanks Chandu. Can the user IDs be selected dynamically in the query? For example, the user IDs might be some other values for another date range.PIVOT (COUNT(id) FOR [User] IN ([22], [31]))pThank you. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
MevaD
Starting Member
32 Posts |
Posted - 2013-12-24 : 10:12:09
|
Perfect. Thank you. |
 |
|
|
|
|