我遇到了以下从COGNOS生成的代码:
CASE
WHEN CASE
WHEN 'FIELD1' LIKE 'VAL1'
THEN 1
WHEN 'FIELD1' LIKE 'VAL2'
THEN 2
WHEN 'FIELD1' LIKE 'VAL3'
THEN 3
ELSE 4
END = 1
THEN 'M'
WHEN CASE
WHEN 'FIELD1' LIKE 'VAL1'
THEN 1
WHEN 'FIELD1' LIKE 'VAL2'
THEN 2
WHEN 'FIELD1' LIKE 'VAL3'
THEN 3
ELSE 4
END = 2
THEN 'Q'
WHEN CASE
WHEN 'FIELD1' LIKE 'VAL1'
THEN 1
WHEN 'FIELD1' LIKE 'VAL2'
THEN 2
WHEN 'FIELD1' LIKE 'VAL3'
THEN 3
ELSE 4
END = 3
THEN 'Y'
ELSE 'T'
END AS 'VAL4'
我无法确定' ='的重要性。运营商跟随' END = nn'。此外,CASE块似乎是重复的,不提供区别值。
答案 0 :(得分:0)
这可能更清楚
CASE
WHEN (
CASE
WHEN 'FIELD1' LIKE 'VAL1' THEN 1
WHEN 'FIELD1' LIKE 'VAL2' THEN 2
WHEN 'FIELD1' LIKE 'VAL3' THEN 3
ELSE 4
END
) = 1 THEN 'M'
WHEN (
CASE
WHEN 'FIELD1' LIKE 'VAL1' THEN 1
WHEN 'FIELD1' LIKE 'VAL2' THEN 2
WHEN 'FIELD1' LIKE 'VAL3' THEN 3
ELSE 4
END
) = 2 THEN 'Q'
WHEN (
CASE
WHEN 'FIELD1' LIKE 'VAL1' THEN 1
WHEN 'FIELD1' LIKE 'VAL2' THEN 2
WHEN 'FIELD1' LIKE 'VAL3' THEN 3
ELSE 4
END
) = 3 THEN 'Y'
ELSE 'T'
END AS 'VAL4'
基本上外壳的每一个'当'选项,另一案例陈述
所以,
如果Field1是其他任何东西,那将是' T'
答案 1 :(得分:0)
比@ SpaceUser7448更简化,这看起来像:
SELECT
CASE
WHEN 'FIELD1' LIKE 'VAL1' THEN 'M'
WHEN 'FIELD1' LIKE 'VAL2' THEN 'Q'
WHEN 'FIELD1' LIKE 'VAL3' THEN 'Y'
ELSE 'T'
END AS 'VAL4'