将2个查询作为子查询连接在一起

时间:2017-05-06 13:27:39

标签: sql join subquery

我有一个像这样的表格参考表:

    id - name - referred_id - referred_name
    1  - mark -   100  -      nick
    2  - david-   100  -      nick 
    3  - mat -    100  -      nick
    4  - patrik-  101  -      robert

我想得到这样的结果:只显示referenced_id => 3条记录

    refered_id - refered_name - Row(count)
    100        - nick         - 3 

我的两个疑问:

    "select count(*) as row(count) from Referral_info where row(count) > 3"

    "select referred_id,referred_name from Referral_info"

如何才能将此查询加入一个? 感谢

1 个答案:

答案 0 :(得分:0)

你在寻找小组吗?

select referred_id,referred_name , count(*) as RowsCount from Referral_info
    group by referred_id,referred_name
    having count(*) > 3