2017-05-06 76 views
1

我喜歡這個節目referrs表:加入2個查詢於一體的子查詢

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

我想結果是這樣的:只顯示referred_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" 

我該如何將這些查詢加入到一箇中? 謝謝

回答

0

您是否在尋找羣組?

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