见下表:
col1 col2
---- ----
1 | a
2 | b
3 | c
4 | a
5 | d
6 | b
7 | e
现在我想只显示非重复记录。这意味着3,5,7。
如何编写查询以获得结果?
答案 0 :(得分:0)
SELECT col1, col2
FROM table
GROUP BY col2
HAVING COUNT(*) = 1;
答案 1 :(得分:0)
SELECT B.*
FROM
(
SELECT col2
FROM YOURTABLE
GROUP BY col2
HAVING COUNT(*)=1
) A,
YOURTABLE B
WHERE A.col2 = B.col2
答案 2 :(得分:0)
SELECT count(*)as cnt,col1,col2 从表 GROUP BY col2 有cnt = 1;
答案 3 :(得分:0)
相信这是清楚和正确的:
SELECT *
FROM table
WHERE
col2 IN (SELECT col2 FROM table GROUP BY col2 HAVING COUNT(*) = 1)