简体   繁体   English

连接或where子句中的DB2 SQL计数

[英]DB2 SQL count in join or where clause

This is probably an amateur question but I'm an amateur ! 这可能是一个业余问题,但我是业余爱好者! ;o) ; 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. 我有几个表:帐户表,官员表,位置表,Web表...官员表没有给我每个帐户的官员人数。

I need to retrieve only the accounts that have more than 20 officers. 我只需要检索拥有20多名职员的帐户。 Should I use the COUNT ? 我应该使用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    
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM