Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

compare o resultado com outra tabela mysql


Tente isso;)
select
    star.type, star.min_amount, t.cnt, t.userids
from star
inner join (
    select  t1.type, count(t2.userid) as cnt, group_concat(t2.userid order by t2.userid) as userids
    from star t1
    inner join user_buys t2 on t1.min_amount <= t2.amount
    group by t1.type
) t on t.type = star.type
order by star.type

SQLFiddle DEMO AQUI