2016-10-26 22 views
-3

enter image description here從SQL表

您好排除特定的價值觀,我有一個表在數據庫中,我只想排除值,其中AccType在(「麗莎」)和AccCodeValue在(「1A」,爲「4G ','1c') 返回一切。

所以預期的結果集是

enter image description here

但得到的實際結果集是

enter image description here

什麼是錯的,我認爲這將是一個簡單的查詢如

Select * From table Where AccType In ('Lisa') And AccCodeval Not In ('1a','1c','4g') 

感謝

+1

提示:使用'WHERE'子句。 –

+0

你有什麼嘗試?任何谷歌搜索將回答這個給你,而不必在這裏發佈像這樣一個新的問題... – SlimsGhost

+0

@seanLange如果答案是在我的評論,我不認爲我會問這個問題。 – nahaelem

回答

2

給這一個鏡頭:

SELECT * 
FROM [yourtable] AS a 
WHERE 
    NOT EXISTS 
    (SELECT * 
    FROM [yourtable] AS b 
    WHERE 
     a.accid = b.accid 
     AND 
     a.acctype = 'lisa' 
     AND 
     a.accCodeValue IN('1a', '4g', '1c')) 
+0

你是男人,謝謝。 – nahaelem

0

我不完全知道你是問什麼,但這樣的事情是什麼,我認爲你正在尋找:

select * from [yourTable] 
where AccType <> 'Lisa' 
and AccCodeValue not in ('1a', '4g', '1c') 
0
SELECT * 
FROM #Acc 
WHERE AccType <> 'Lisa' AND AccCode NOT IN ('1a','4g','1c')