sql查询?question:find the 在同一城市经营“房屋”和“公寓”类物业的全体员工人数

qxsslcnc  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(236)

我正在使用dreamhome数据库。我的问题是:
选择(staffno)from propertyforrent where staffno in(选择staffno from propertyforrent where type='house'联合选择staffno from propertyforrent where type='flat')和city='glasgow'

我试过这个。但这是错误的。

uqdfh47h

uqdfh47h1#

使用聚合:

select distinct staffno
from t
where type in ('House', 'Flat')
group by staffno, city
having count(distinct type) = 2;

这是极少数几个 select distinct 用于 group by . 你没有要求城市,所以这只是返回员工人数,即使有多个城市。

相关问题