sql - to get the multiple maximum-count of repeated values in mysql -
how can output maximum count of repeated values table , contains repeated values corresponding column such way there multiple different distinct values having maximum-counts .
thanks !
consider r table data below :
+---------+------------+-------------+--------------+ | bill_no | bill_date | customer_id | total_amount | +---------+------------+-------------+--------------+ | 101 | 2012-04-10 | c001 | 64 | | 102 | 2012-04-10 | c002 | 8 | | 103 | 2012-04-11 | c002 | 140 | | 104 | 2012-04-13 | c001 | 29 | | 105 | 2012-04-12 | c003 | 125 | | 106 | 2012-04-16 | c004 | 258 | +---------+------------+-------------+--------------+
we see here maximum count(customer_id)
same c001
, c002
. want both values.
the final output should follows:
customer_id | count(customer_id) //max value ----------------+----------------------- c001 | 2 c002 | 2 ----------------+-----------------------
so, guessing,
select distinct g.customer_id, g.cnt ( select distinct customer_id, count(customer_id) cnt table group customer_id ) g inner join ( select max(s.cnt) max_cnt ( select distinct customer_id, count(customer_id) cnt table group customer_id ) s ) m on m.max_cnt = g.cnt
do trick?
Comments
Post a Comment