| Author |
Topic |
|
wilkinj
Starting Member
2 Posts |
Posted - 2010-06-24 : 11:22:17
|
| Hi Guysi'm a real newbie to SQL...pretty much at the Hello World stage. I need some help with counting rows from a table where a condition is met. My table looks like this:site,userName,recordName,month,yearNY, bob, ABC.L, 5, 2010NY, bob, DEF.L, 5, 2010NY, bob, GRF.L, 5, 2010NY, bob, ABC.L, 6, 2010NY, bob, CDO.L, 6, 2010NY, bob, REF.L, 7, 2010NY, fred, ABC.L, 5, 2010NY, fred, LED.L, 5, 2010NY, fred, CAD.L, 5, 2010So, i want to summarize the unique number of recordNames for a given userName in a particular month. So the result of what i'm looking for might be:NY, bob, 5, 3 (where 5 = month and 3 = the count of distinct recordNames in month 5)I hope this makes sense. Any assistance would be greatly appreciated.Thanks, regards |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-06-24 : 11:33:00
|
| SELECT site, UserName, Month, Year, Count(*)FROMSomeTableGROUP BY site, UserName, Month, YearIf you want to limit to a particular month/year, you'd add a where clause before the Group By--Gail ShawSQL Server MVP |
 |
|
|
wilkinj
Starting Member
2 Posts |
Posted - 2010-06-24 : 12:36:38
|
quote: Originally posted by GilaMonster SELECT site, UserName, Month, Year, Count(*)FROMSomeTableGROUP BY site, UserName, Month, YearIf you want to limit to a particular month/year, you'd add a where clause before the Group By--Gail ShawSQL Server MVP
Thank you so much for your prompt response. This works a treat!Regards |
 |
|
|
|
|
|