Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有以下数据库表
id Name 1 X 2 X 3 X 4 Y 5 Z 6 Z
我想要做的是检索其 Name 列具有相同值的行,无论 Name 是什么。换句话说,名称将不会在 SQL 查询中输入。
结果表:
id Name 1 X 2 X 3 X 5 Z 6 Z
这应该是什么SQL?
提前致谢
SELECT a.* FROM tableName a INNER JOIN ( SELECT Name FROM TableName GROUP BY Name HAVING COUNT(*) > 1 ) b ON b.Name = a.Name
使用IN(虽然我更喜欢 JOIN)
IN
SELECT * FROM tableName WHERE Name IN ( SELECT Name FROM TableName GROUP BY Name HAVING COUNT(*) > 1 )