compare result with other table mysql

后端 未结 2 1282
情歌与酒
情歌与酒 2021-01-16 16:58

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.         


        
2条回答
  •  醉话见心
    2021-01-16 17:51

    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
    

提交回复
热议问题