Count same values in column SQL Server -
i trying count same values in column , want return count there off.
| item | count | +-------+-------+ | green | 1 | | green | 2 | | green | 3 | | red | 1 | | red | 2 |
i tried
row_number() on (order item) row
but counts each line 1 - 1000
how accomplish this?
you'll want include partition by
clause row_number function. makes row_number restart 1 each new type of item.
row_number() on (partition item order item) row
this give result like:
item row green 1 green 2 green 3 red 1 red 2
Comments
Post a Comment