Mysql
 sql >> Database >  >> RDS >> Mysql

Come faccio a selezionare una riga con conteggio massimo eseguendo un gruppo per

Puoi provare con il group by e having clausole:

select t.user_name, t.thread_id , count(*) as max_count
from tbl t
group by t.user_name, t.thread_id
having count(*) = ( select count(*) as ttl
                    from tbl
                    where thread_id = t.thread_id
                    group by user_name
                    order by ttl desc
                    limit 1 )