开发者

DB2 SQL count in join or where clause

开发者 https://www.devze.com 2022-12-23 20:43 出处:网络
This is probably an amateur question but I\'m an amateur !;o) I have several tables: Account table, Officer table, Location table, Web table...

This is probably an amateur question but I'm an amateur ! ;o)

I have several tables: Account table, Officer table, Location table, Web table... The Officer table doesn't give me the number of officers per account.

I need to retrieve only the开发者_运维知识库 accounts that have more than 20 officers. Should I use the COUNT ? If so, how ?

Your help is greatly appreciated. Thanks.

Pat


Update:

select a.id, a.eff-date, l.address, l.city, c.phonenumber
from Account a 
left outer join location l on a.id = l.id
left outer join contact c on a.id = c.id
where a.id in (
    select a.id
    from Account a
    inner join Officer ao on a.id = ao.id
    group by a.id
    having count(*) > 20    
)
0

精彩评论

暂无评论...
验证码 换一张
取 消