sql-server-2012 - 从 SQL Server 中具有相等条件的表中选择
问题描述
我想实现以下目标:
select record
where (`adslocationdescription` = "jawa timur" and `type` = 1) or
(`adslocationdescription` != 'jawa timur and `type` = 2)
但如果adscampaigncode
有一个等于 ( adslocationdesc
= "jawa timur" and type
=2) 的记录,则不应选择任何数据。
解决方案
类似于(代码未测试):
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')
推荐阅读
- html - 仅在移动设备上引导响应行为
- angular - 在 Angular 中,如何防止用户从当前选项卡更改?
- c - 文件末尾是否有一个终止字符(不是 EOF),它将作为最后一个字符读取?
- list - 取一个值并将其传递给一个结构列表并返回一个具有相应值的列表
- wpf - 具有多种颜色 WPF 的进度条
- excel - 多个单元格中的自动求和
- react-redux - 如何在不使用函数组件的情况下将新值(例如 const)分配给反应类使用状态的新值?
- c++ - 创建数组时出错:表达式必须具有常量值
- html - 没有标签的html中写纯文本是否合适?
- function - 在复制 LabView VI 时寻求帮助 - 更改输入时图形出现错误