我不确定这个案例陈述的序列有什么问题。 我已经在线查看,语法似乎是正确的,但我收到错误丢失的关键字。 任何帮助将不胜感激!
CASE
when A = '1' then
when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '2' then
when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '3' then
when sequence_number =7 then 9
when sequence_number =8 then 9
end
else T.number
end as number
答案 0 :(得分:2)
您需要在每个分支中使用第二个CASE
语句,否则您需要结合条件
CASE
when A = '1' and sequence_number = 5 then 9
when A = '1' and sequence_number = 6 then 9
when A = '2' and sequence_number = 5 then 9
...
else T.number
end as number
或
CASE
when A = '1' then
case when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '2' then
case when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '3' then
case when sequence_number =7 then 9
when sequence_number =8 then 9
end
else T.number
end as number
答案 1 :(得分:2)
最简单的选择似乎是:
case
when (A in (1,2) and sequence_number in (5,6)) or
(A in (3 ) and sequence_number in (7,8))
then 9
else t.number
end
答案 2 :(得分:0)
@mikeb是正确的 - 你需要一个额外的CASE。
我在测试时遇到了Number
列的问题;只是猜测,但也许甲骨文作为一个保留字窒息?如果您和我一样获得ORA-01747: invalid user.table.column, table.column, or column specification
例外,请将其更改为Num
或TheNumber
。
这是更新的CASE:
CASE
when A = '1' then
case
when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '2' then
case
when sequence_number = 5 then 9
when sequence_number = 6 then 9
end
when A = '3' then
case
when sequence_number =7 then 9
when sequence_number =8 then 9
end
else T.number
end as number