我想從下表中獲得結果。獲取除ID = 102的蘋果以外的所有ID和treetype。SQL Server中的替代項
Id TreeType
---------------------
99 Apple
99 Mango
102 Orange
101 Blackberry
102 Apple
結果會是。
Id TreeType
---------------------
99 Apple
99 Mango
102 Orange
101 Blackberry
我們可以從下面的查詢中得到結果的一種方法。
select id, TreeType
from x
except
select id, TreeType
from x
where id = 102 and TreeType = 'Apple'
它有可能從一個select語句得到結果嗎?
我只是想避免因爲在實際情況下它對我而言成本非常高昂。
'其中id <> 102 OR treetype <>「Apple'' –