我使用的是Dreamhome数据库。这是我的查询。
select (staffno) from propertyforrent where staffno in(select staffno from propertyforrent where type ='House'unionselect staffno from propertyforrent where type ='Flat')and city= 'Glasgow')
我已经试过了。但它是错误的。
使用聚合。
select distinct staffno
from t
where type in ('House', 'Flat')
group by staffno, city
having count(distinct type) = 2;
这是极少数的情况之一 select distinct
是与 group by
. 你并没有要求城市,所以这只是返回员工编号,即使有多个城市。