1

我只需要过滤在 x 和 y 列中具有相同值的这些表行。

 _______________________________________
|
|    x    |      y     |      name     |
________________________________________
|
|   1     |      2     |     A         |
|______________________________________
|   2     |      1     |      B        |
|______________________________________
|   1     |      2    |     C          | 
|_______________________________________  

最终结果应该是我有 A 和 C 结果。我需要过滤这些具有相同 x 和 y 值的行。

 _______________________________________
|
|    x    |      y     |      name     |
________________________________________
|
|   1     |      2     |     A         |
|______________________________________
 ______________________________________
|   1     |      2    |     C          | 
|_______________________________________  

我已经尝试过这段代码,但我只成功了一个字段。

select * 
from auto 
where x in (
        select x 
        from auto 
        group by x 
        having count(*) > 1
    );
4

2 回答 2

3
SELECT t1.*
FROM tablename t1, tablename t2
WHERE t1.x = t2.x
AND t1.y = t2.y
AND t1.primary_key != t2.primary_key
于 2012-07-05T17:08:12.543 回答
2
select * from 
auto a, ( SELECT x, y, COUNT(*) FROM auto GROUP BY x, y HAVING COUNT(*) > 1 ) b
where a.x = b.x
and a.y = b.y

会将您的其他问题标记为重复

于 2012-07-05T18:31:36.863 回答