我需要一个查询,它必须获取其中一个字段值多次存在的所有记录,
表会像
S_NO ID
S100 I01
S101 I01
S102 I02
S103 I00
S104 I02
由于某些 ID 存在不止一次,因此结果应该是
S100 I01
S101 I01
S102 I02
S104 I02
尝试以下查询:
SELECT S_NO,ID
FROM your_table
WHERE ID IN (SELECT ID FROM your_table GROUP BY ID HAVING COUNT(*) > 1)
尝试
SELECT *
FROM Table1
WHERE id IN
(
SELECT id
FROM Table1
GROUP BY id
HAVING COUNT(*) > 1
)
输出:
| S_NO | 身份证 | -------------- | S100 | I01 | | S101 | I01 | | S102 | I02 | | S104 | I02 |
这是SQLFiddle演示