表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 ,不管销售是不是大于手工都取销售,这个条件,语句应该怎么判断,谢谢。
case when xs>sg or spid in(个别spid) then xs
else sg end
优先判断一下你特殊的编码,再判断是否大于,
case when spid in('A1005','B1345','A444') then xs
when xs>sg then xs else sg end end as 判断后
select rq,spid,xs,sg,
case when spid='xxx' then xs
when xs>sg then xs else sg end
from a
select
rq,
spid,
xs,
sg,
case when spid in(spid01,spid02,spid03) or xs>sg then xs
else sg end type
type:结果字段别名
spid01,spid02,spid03:所谓的个别spid