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 |
|
rtutus
Aged Yak Warrior
522 Posts |
Posted - 2007-10-23 : 11:44:56
|
| Hi,I use group by myItem, that displays rows for each value of myItem.I want at the end of each group for each specific myItem, I want an extra row to tell me the count of the rows for that group.How do i do that please. Here s what I need, for example for this set of rows:myItem colum2 colum3711056 22662 Finances / -2291 -2479916711056 22663 Finances / -2380 -2576255711056 43428 Cda) -323 -349635711056 43428 . -B-(Cda) -44 -47628711057 44348 . -B-(Cda) -355 -384273711057 47033 . -B-(Cda) -1278 -1383384I need 2 extra rows, one at the end of the items 711056 telling me there are 4 rows for the item 711056 and one row at the very end telling me there are: 2 rows for the item: 711057Thanks a lot. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-23 : 12:04:28
|
COUNT(*) OVER (PARTITION BY MyItem) E 12°55'05.25"N 56°04'39.16" |
 |
|
|
stonebreaker
Yak Posting Veteran
92 Posts |
Posted - 2007-10-23 : 12:13:50
|
| You could do this a couple of ways. I would probably declare a cursor for distinct values of myItem, then do two select statements:select myItem, column2, column3where myItem = value of cursorselect myItem, count(*)where myItem = value of cursorfetch next from cursor |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-24 : 03:11:40
|
quote: Originally posted by stonebreaker You could do this a couple of ways. I would probably declare a cursor for distinct values of myItem, then do two select statements:select myItem, column2, column3where myItem = value of cursorselect myItem, count(*)where myItem = value of cursorfetch next from cursor
Did you read Peso's reply?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|