sql server - SQL count distinct values of another value -


say have table looks column names (cusip_nbr, partc_nbr) lets called table title table_cusip (sorry don't know how format btw)

cusip_nbr ----- partc_nbr

00162q106 ------------ 0756
00162q106 ------------ 0231
00162q106 ------------ 0756
00162q106 ------------ 0231
231292106 ------------ 0412
231292106 ------------ 0395
231292106 ------------ 0101
231292106 ------------ 0291
43129u101 ------------ 0756
43129u101 ------------ 0395
43129u101 ------------ 0921
43129u101 ------------ 0756

what sql code can write return table (basically @ cusip_nbr , see how many distinct participant numbers there per cusip_nbr)? -> 00162q106 has 2 distinct members, 231292106 has 4, , 43129u101 has 3. (this snip of table have 1,300 cusip_nbrs need count members for)

cusip_nbr ---- nbr_of_members

00162q106 ----------------- 2
23129106 --------------------4
43129u101------------------ 3

select cusip_nbr, count(distinct partc_nbr) nbr_of_members table_cusip  group cusip_nbr 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -