sql >> Base de Datos >  >> RDS >> Mysql

comparar el resultado con otra tabla mysql

Prueba esto;)

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

DEMOSTRACIÓN DE SQLFiddle AQUÍ