Mysql
 sql >> Base de données >  >> RDS >> Mysql

comparer le résultat avec une autre table mysql

Essayez ceci ;)

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

DÉMO SQLFiddle ICI