获取具有相同值的行

发布于 2025-01-19 07:21:38 字数 207 浏览 0 评论 0原文

在此处输入图像描述 这是我的表格,其中包含公寓业主、公寓所在房屋的号码等信息。 同一公寓的业主可以是两个不同的人,因为这是负责列“分数”,它显示了一个人拥有公寓的某一部分。

我的任务是显示一套公寓由两个人拥有的所有信息?

因此,结果我应该得到 14 号门牌号的 9 号公寓

enter image description here
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红焚 2025-01-26 07:21:38

我认为您想要:

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

上述逻辑将检测到任何拥有多个唯一所有者的房屋和公寓。

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.

妞丶爷亲个 2025-01-26 07:21:38

这对我有用:

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 并参考对于这个问题:
IN 子句中的 MySQL 多列

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:
MySQL multiple columns in IN clause

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文