简体   繁体   English

获取具有相同值的行

[英]Get rows with the same value

在此处输入图像描述 This is my table in which the information about the owner of the apartment, the number of the house in which the apartment is located, etc. The owners of the same apartment can be two different people, for this is responsible column Fraction, which shows a certain part of the apartment owned by a person.这是我的表格,其中包含有关公寓所有者的信息,公寓所在房屋的编号等。同一公寓的所有者可以是两个不同的人,因为这是负责的分数列,它显示某人拥有的公寓的某个部分。

My task is to display all the information if one apartment is owned by two people?如果一间公寓由两个人拥有,我的任务是显示所有信息?

Accordingly, as a result, I should get apartment number 9 in house number 14因此,结果,我应该得到 14 号门牌的 9 号公寓

I think you want:我想你想要:

SELECT House_Number, Apartment_Number
FROM yourTable
GROUP BY House_Number, Apartment_Number
HAVING MIN(Owner) <> MAX(Owner);

The above logic will detect anyone house and apartment having more than one unique owner.上述逻辑将检测拥有多个唯一所有者的任何房屋和公寓。

This works for me:这对我有用:

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)

See this db<>fiddle and also refer to this SO question:请参阅此db<>fiddle并参考此 SO 问题:
MySQL multiple columns in IN clause MySQL IN 子句中的多个列

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

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