compare result with other table mysql

后端 未结 2 1271
情歌与酒
情歌与酒 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
    
    0 讨论(0)
  • 2021-01-16 17:59

    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

    0 讨论(0)
提交回复
热议问题