SQL查询语句中如何用case when 返回多个字段?

2025-04-08 12:38:48
推荐回答(1个)
回答1:

一个字段一个字段的判断
就是a和b都不等于0返回的话
select table.*,
(case when a<>0 and b<>0 then c%a
else 0 end) as e,
(case when a<>0 and b<>0 then (c%a)%b
else 0 end) as d
from table where ……

如果是其他情况,再添加case when条件