Выберите из таблиц в SQL Server с равными условиями - PullRequest
0 голосов
/ 08 января 2019

Пожалуйста, посмотрите мой снимок данных здесь

Я хочу добиться следующего:

select record 
where (`adslocationdescription` = "jawa timur" and `type` = 1) or     
      (`adslocationdescription` != 'jawa timur and `type` = 2)

, но если adscampaigncode имеет запись, равную (adslocationdesc = "jawa timur" и type = 2), данные не должны выбираться.

1 Ответ

0 голосов
/ 08 января 2019

Что-то вроде (код не проверен):

select * from myTable
where (AdsLocationDescription = 'Jawa Timur' AND (Type = 1 OR Type = 2))
AND AdsCampaignCode NOT IN
-- this subquery gets AdsCampaignCodes that 
-- DO have LocationDescription of Jawa Timur
(select distinct AdsCampaignCode
from myTable
where AdsLocationDescription = 'Jawa Timur')
...