mysql - 当 count > x 时显示单独的行

标签 mysql sql

我有一个数据库,其中包含 record_number(PRIMARY)、owner_name、地址。

我想识别拥有多个属性(property)的owner_name,并列出owner_name 拥有的每项属性(property)。

类似于:

record_number   | owner_name      |  address
1               | Smith           |  123 Main
7               | Smith           |  1 Some Street
12              | Smith           |  77 Dude Ln
19              | Jones           |  Some address
21              | Jones           |  Some Different address
47              | Jones           |  Yet another address
106             | Davis           |  You're getting the idea?
139             | Davis           |  All of these are different!
141             | Davis           |  They keep changing
158             | Davis           |  When will it end?

最佳答案

select record_number, owner_name, address
from your_table
where owner_name in
(
  select owner_name
  from your_table
  group by owner_name
  having count(*) > 1
)
order by owner_name, record_number

关于mysql - 当 count > x 时显示单独的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34763073/

相关文章:

mysql - 选择 MySQL 中特定列的匹配行数

MYSQL游标循环,多跑一轮,为什么?

mysql - 对列中的值进行 Group by 子句

sql - sql组合

sql - 如果表A中的值不为空,如何从表B中获取值

c# - 如何在整个应用程序中使用 mysqlconnection

php - 来自远程文件的 SQL 注入(inject)

sql - 从按两列分组的两个表中选择不匹配的行

mysql - SQL CSV 跨表导入/导出发布数据

MySQL 过程创建时出错