mysql - Select count of rows from the same table -


hi have table below , need select count of different trade ids given distinct orderids unable in mysql format

+-----------+---------+ | orderid   |tradeid  | +===========+=========+ | 1         | 58761   | +-----------+---------+ | 1         | 58762   |  +-----------+---------+ | 2         | 58763   |  +-----------+---------+ | 2         | 58764   |  +-----------+---------+ | 2         | 58765   | +-----------+---------+ 

where result required

+-----------+---------+ | orderid   |count    | +===========+=========+ | 1         | 2       | +-----------+---------+ | 2         | 4       |  +-----------+---------+ 

just count / group by

select orderid, count(*)  some_table  group orderid 

sql fiddle here:-

http://www.sqlfiddle.com/#!9/305630/1

note if wanted of distinct tradeids each orderid use

select orderid, count(distinct tradeid)  some_table  group orderid 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -