I have 2 table I select and count compare item form 2 tables, also after compare I need to compute how many item contain in other table.
select
results.
select
star.type, star.min_amount, t.cnt, t.userids
from star
inner join (
select t1.type, t1.min_compare, 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
HAVING cnt >= t1.min_compare
) t on t.type = star.type
order by star.type
Try this;)
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 HERE