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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -