数据查询问题

表A,4个字段

rq,spid,xs,sg

select rq,spid,xs,sg,case xs>sg then xs else sg end from a

where rq>=

and rq<=

一张表字段:日期rq,商铺编号spid,销售xs,手工xs 按时间段统计商铺销售,如果销售大于手工取销售,其他取手工。

问题:有个别spid ,不管销售是不是大于手工都取销售,这个条件,语句应该怎么判断,谢谢。

FineReport ysbin 发布于 2023-4-4 15:09
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
0
free_zzLv6中级互助
发布于2023-4-4 15:14(编辑于 2023-4-4 15:16)

case when xs>sg or spid in(个别spid) then xs 

else sg end 

最佳回答
0
CD20160914Lv8专家互助
发布于2023-4-4 15:14(编辑于 2023-4-4 15:15)

优先判断一下你特殊的编码,再判断是否大于,

case when spid in('A1005','B1345','A444') then xs 

when xs>sg then xs else sg end end as 判断后

最佳回答
0
用户k6280494Lv6资深互助
发布于2023-4-4 15:14(编辑于 2023-4-4 15:15)

select rq,spid,xs,sg,

case when  spid='xxx' then xs

 when  xs>sg then xs else sg end 

from a

where rq>=

and rq<=

最佳回答
0
AzureLLv2见习互助
发布于2023-4-4 16:00(编辑于 2023-4-4 16:01)

select 

rq,

spid,

xs,

sg,

case when spid in(spid01,spid02,spid03) or xs>sg then xs 

else sg end type

    from a

    where rq>=

        and rq<=

type:结果字段别名

spid01,spid02,spid03:所谓的个别spid

  • 4关注人数
  • 252浏览人数
  • 最后回答于:2023-4-4 16:01
    请选择关闭问题的原因
    确定 取消
    返回顶部