Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Vergleichen Sie das Ergebnis mit einer anderen Tabelle mysql

Probieren Sie es aus;)

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 HIER