我只有一行数据,如下所示:
dyn1 dyn2 dyn3 chg
1 0 1 768
现在我想写一个
这样的条件条件Case when dyn1 = 1 then 7 When dyn2=1 then 7 When dyn3=1 then 7 End
现在,以上记录表明它没有检查dyn3值,因为它将dyn1值设为true。
如何处理此代码?
答案 0 :(得分:0)
我假设您需要在select语句中返回这些值,也许对您有帮助。
SELECT CASE WHEN dyn1 = 1 THEN 7 END,
CASE WHEN dyn2 = 1 THEN 7 END,
CASE WHEN dyn3 = 1 THEN 7 END
FROM (SELECT 1 AS dyn1, 1 AS dyn2, 1 AS dyn3 FROM dual);
或者,也许您只希望在其列中输入
SELECT CASE WHEN dyn1 = 1 THEN 7 END ||
CASE WHEN dyn2 = 1 THEN 7 END ||
CASE WHEN dyn3 = 1 THEN 7 END
from (select 1 as dyn1, 1 as dyn2, 1 as dyn3 from dual);