2012-10-18 88 views
0

有人可以幫我這個查詢請:重複查詢

我有哪裏的客戶有多個記錄的數據(在一個單一的表,這是讀入一個表中的平面文件),例如

Name Policy 
Fred SSS 
Fred SST 
Joe SSS 

我需要提取所有記錄,其中Policy ='SSS'但該客戶只有'SSS'策略。因此,只有喬從上空

+1

如果指定了各種SQL您正在使用 – podiluska

回答

2
select name 
from yourtable 
group by name 
having count(policy)=1 and max(policy)='SSS' 
+0

完美的作品,非常感謝它有助於返回 –

1
SELECT Name 
FROM tableName a 
WHERE Policy = 'SSS' 
GROUP BY Name 
HAVING COUNT(*) = (SELECT COUNT(*) FROM tableName b WHERE a.Name = b.Name) 

SQLFiddle Demo