You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SQL SELECT语句中添加特定公司代码的部门例外规则?

解决方案

修改后的SQL语句如下:

select top (1000000) companyid 
,companyfullname
,company_code
,division
,reportingname
,division_name
,country 
,accountname
from totaldw.dbo.companymap
where 
    company_code not in ('1760','1785','1831','1740')
    or 
    (company_code = '1771' and division in ('01188','01189'))

逻辑说明

  1. 先从原排除列表中移除1771,确保基础规则是排除1760、1785、1831、1740这几个公司代码的所有记录。
  2. 通过OR追加例外判断:仅当公司代码为1771且对应的division是01188或01189时,保留该条记录,1771下其他division的记录仍会被排除。

内容的提问来源于stack exchange,提问作者courty340

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 04:15:38