CID F_ID NME
1 A QR
1 B QB
2 A QR
3 B QB
4 A QR
4 B QB
结果应采用以下方式
CID F_ID NME
1 A QR
1 B QB
4 A QR
4 B QB
CID是CUST ID,F_ID是FUTURE_ID,NME是NAME。
查询结果应仅返回两个 F_ID-A和B
答案 0 :(得分:0)
这是编写此查询的一种典型方式:
SELECT t1.CID, t1.F_ID, t1.NME
FROM yourTable t1
INNER JOIN
(
SELECT CID
FROM yourTable
WHERE F_ID IN ('A', 'B')
GROUP BY C_ID
HAVING MIN(F_ID) <> MAX(F_ID)
) t2
ON t1.CID = t2.CID;