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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -