0

我有一张这样的桌子

custno, type, color
A1234, B, Red
A1234, C, Blue
A1277, B, Red
A1288, A, Black
A1288, B, Red
A1289, A, Black

我只需要检索仅找到一次的唯一记录 A1277 和 A1289。

4

3 回答 3

2

这将显示custNO在结果列表中,

SELECT  custNo
FROM    tableName
GROUP   BY custNO
HAVING  COUNT(*) = 1

但如果你想得到整行,

SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT  custNo
            FROM    tableName
            GROUP   BY custNO
            HAVING  COUNT(*) = 1
        ) b ON a.custNo = b.custNo
于 2013-03-12T15:07:01.733 回答
1
SELECT custno
FROM yourTable
GROUP BY custno
HAVING COUNT(*) = 1

示例小提琴

于 2013-03-12T15:07:10.717 回答
0

试试这个,因为这样可以防止代价高昂的连接操作——

SELECT custno,type,color FROM ( SELECT custno, type, color, COUNT(custno) OVER(PARTITION BY custno) CNT FROM tableName )TMP WHERE CNT=1

于 2013-03-15T07:25:37.073 回答