0
重複的記錄我有數據表給予以下結果:獲取從表
number code
1 A
1 B
1 A
2 B
2 A
3 A
4 B
我如何找到有碼錶不同的數作爲A.數應該只有一個代碼表和沒有的B表。
對於上表中:我的答案是3,由於只有代碼A.
重複的記錄我有數據表給予以下結果:獲取從表
number code
1 A
1 B
1 A
2 B
2 A
3 A
4 B
我如何找到有碼錶不同的數作爲A.數應該只有一個代碼表和沒有的B表。
對於上表中:我的答案是3,由於只有代碼A.
SELECT DISTINCT a.number
FROM TableName a
WHERE a.Code = 'A'
AND NOT EXISTS (Select 1
FROM TableName b
WHERE a.number = b.number
AND b.Code = 'B')
如果只想A
,一種方法是聚集:
select t.number
from t
group by t.number
having min(code) = 'A' and max(code) = 'A';