获取具有相同值的行
Get rows with the same value
这是我的table,里面有公寓主人的信息,公寓所在的门牌号等等。
同一间公寓的业主可以是两个不同的人,因为这是负责栏Fraction,它显示了一个人拥有的公寓的某个部分。
我的任务是如果一间公寓由两个人拥有,则显示所有信息?
据此,我应该得到14号门牌的9号公寓
我想你想要:
SELECT House_Number, Apartment_Number
FROM yourTable
GROUP BY House_Number, Apartment_Number
HAVING MIN(Owner) <> MAX(Owner);
以上逻辑将检测拥有多个唯一所有者的任何房屋和公寓。
这对我有用:
select Owner
from HOMES
where (House_Number, Apartment_Number) in (select House_Number
,Apartment_Number
from HOMES
group by House_Number
,Apartment_Number
having count(*) > 1)
查看此 db<>fiddle 并参考此 SO 问题:
我的任务是如果一间公寓由两个人拥有,则显示所有信息?
据此,我应该得到14号门牌的9号公寓
我想你想要:
SELECT House_Number, Apartment_Number
FROM yourTable
GROUP BY House_Number, Apartment_Number
HAVING MIN(Owner) <> MAX(Owner);
以上逻辑将检测拥有多个唯一所有者的任何房屋和公寓。
这对我有用:
select Owner
from HOMES
where (House_Number, Apartment_Number) in (select House_Number
,Apartment_Number
from HOMES
group by House_Number
,Apartment_Number
having count(*) > 1)
查看此 db<>fiddle 并参考此 SO 问题: