katemaomao 2023-07-30 18:31 采纳率: 50%
浏览 51
已结题

SQL 报错 在应使用条件的上下文(在 ',' 附近)中指定了非布尔类型的表达式


select a.MonthCode,b.STDskucode,a.skucode,c.sku_cn,
case when a,Channel='Omni KC' and a.SubChannel='NCA' then 'NCA' when a.Channel='Omni KC' and a.SubChannel<>'NCA' then 'NKC' else a.Channel end as DPChannel,
sum(a.GSV)/1000 as GSV,
0 as NIV
from DP_Forecast as a
inner join MD_STDSKU as b on b.stdskucode=a.stdskucode 
inner join md_sku  as c on a.skucode=c.skucode
group by select a.MonthCode,b.STDskucode,a.skucode,c.sku_cn, 
case when a,Channel='Omni KC' and a.SubChannel='NCA' then 'NCA' when a.Channel='Omni KC' and a.SubChannel<>'NCA' then 'NKC' else a.Channel end 
union all
select d.MonthCode,b.STDskucode,d.skucode,c.sku_cn,
case when d.DivisionDesc='Omni KC' and d.RegionDesc='NCA' then 'NCA' when d.DivisionDesc='Omni KC' and d.RegionDesc<>'NCA' then 'NKC' else d.DivisionDesc end  as DPChannel ,
sum(d.GSV)/1000 as GSV,
sum(d.NIV)/1000 as NIV
from DW_PrimarySales as d
inner join MD_STDSKU as b on b.stdskucode=d.stdskucode
inner join md_sku as c on d.skucode=c.skucode
where d.MonthCode between '2023_M01' and '2023_M06'
group by d.MonthCode,b.STDskucode,d.skucode,c.sku_cn,
case when d.DivisionDesc='Omni KC' and d.RegionDesc='NCA' then 'NCA' when d.DivisionDesc='Omni KC' and d.RegionDesc<>'NCA' then 'NKC' else d.DivisionDesc end 

报错信息如下

消息 4145,级别 15,状态 1,第 18 行
在应使用条件的上下文(在 ',' 附近)中指定了非布尔类型的表达式。
消息 4145,级别 15,状态 1,第 27 行
在应使用条件的上下文(在 ',' 附近)中指定了非布尔类型的表达式。

完成时间: 2023-07-30T18:13:56.2767725+08:00



```sql


```

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-07-30 18:37
    关注

    加上点缩进啊

    SELECT a.MonthCode, b.STDskucode, a.skucode, c.sku_cn,
        CASE
            WHEN a.Channel = 'Omni KC' AND a.SubChannel = 'NCA' THEN 'NCA'
            WHEN a.Channel = 'Omni KC' AND a.SubChannel <> 'NCA' THEN 'NKC'
            ELSE a.Channel
        END AS DPChannel,
        SUM(a.GSV)/1000 AS GSV,
        0 AS NIV
    FROM DP_Forecast AS a
    INNER JOIN MD_STDSKU AS b ON b.stdskucode = a.stdskucode 
    INNER JOIN md_sku AS c ON a.skucode = c.skucode
    GROUP BY a.MonthCode, b.STDskucode, a.skucode, c.sku_cn, 
        CASE
            WHEN a.Channel = 'Omni KC' AND a.SubChannel = 'NCA' THEN 'NCA'
            WHEN a.Channel = 'Omni KC' AND a.SubChannel <> 'NCA' THEN 'NKC'
            ELSE a.Channel
        END 
    UNION ALL
    SELECT d.MonthCode, b.STDskucode, d.skucode, c.sku_cn,
        CASE
            WHEN d.DivisionDesc = 'Omni KC' AND d.RegionDesc = 'NCA' THEN 'NCA'
            WHEN d.DivisionDesc = 'Omni KC' AND d.RegionDesc <> 'NCA' THEN 'NKC'
            ELSE d.DivisionDesc
        END AS DPChannel,
        SUM(d.GSV)/1000 AS GSV,
        SUM(d.NIV)/1000 AS NIV
    FROM DW_PrimarySales AS d
    INNER JOIN MD_STDSKU AS b ON b.stdskucode = d.stdskucode
    INNER JOIN md_sku AS c ON d.skucode = c.skucode
    WHERE d.MonthCode BETWEEN '2023_M01' AND '2023_M06'
    GROUP BY d.MonthCode, b.STDskucode, d.skucode, c.sku_cn,
        CASE
            WHEN d.DivisionDesc = 'Omni KC' AND d.RegionDesc = 'NCA' THEN 'NCA'
            WHEN d.DivisionDesc = 'Omni KC' AND d.RegionDesc <> 'NCA' THEN 'NKC'
            ELSE d.DivisionDesc
        END;
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 8月7日
  • 已采纳回答 7月30日
  • 创建了问题 7月30日

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上