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 |
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2011-04-07 : 08:01:26
|
Hi,I have this query SELECT tt.intTempeteId,tt.datDateTempete,te.strNom,reg.strNomFROM tblTempete as ttINNER JOIN tblRegionEcole as re ON tt.intTempeteId = re.intTempeteIdINNER JOIN tblEcole as te ON re.intEcoleId = te.intEcoleIdINNER JOIN tblRegion as reg ON reg.intRegionId = te.intRegionIdWHERE tt.datDateTempete = '2011-04-05' That return this Is there a way to put another row that will count how many reg.strNomEx: How many reg.strNom École Donat-Robichaud Région de Shédiac 5 École Père-Edgar-T.-LeBlanc Région de Shédiac 5Polyvalente Louis-J.-Robichaud Région de Shédiac 5École Mgr.-Francois-Bourgeois Région de Shédiac 5École Grande-Digue Région de Shédiac 5École Soleil Levant Région de Saint-Louis de Kent 2École La Marée Montante Région de Saint-Louis de Kent 2 TksLuc |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2011-04-07 : 08:15:52
|
For SQL2005 and above, try:,COUNT(*) OVER (PARTITION BY reg.strNom) AS strNomCount |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-04-07 : 08:17:26
|
| To do it as rows you'd have to use union statements for each row. To do it as columnstt.intTempeteId,tt.datDateTempete,te.strNom,reg.strNom,count(*) OVER(partition by strNom) as RecordsJimEveryday I learn something that somebody else already knew |
 |
|
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2011-04-07 : 08:22:55
|
Hi,tks for the response i will try it!Lucquote: Originally posted by jimf To do it as rows you'd have to use union statements for each row. To do it as columnstt.intTempeteId,tt.datDateTempete,te.strNom,reg.strNom,count(*) OVER(partition by strNom) as RecordsJimEveryday I learn something that somebody else already knew
|
 |
|
|
lucsky8
Posting Yak Master
105 Posts |
Posted - 2011-04-07 : 10:48:41
|
| Hi tks jimf and Ifor it work!I did't know you could do that!!! |
 |
|
|
|
|
|
|
|