sql CASE 语法的问题:表达式代表什么意思
CASE 具有两种格式:
Simple CASE function:
CASE input_expression
WHEN when_expression THEN result_expression
[ ...n ]
[ ELSE else_result_expression ]
END
Searched CASE function:
CASE
WHEN Boolean_expression THEN result_expression
[ ...n ]
[ ELSE else_result_expression ]
END
THEN result_expression 是当 input_expression = when_expression 计算结果为 TRUE,或者 Boolean_expression 计算结果为 TRUE 时返回的表达式。
问题:这里的表达式input_expression 或Boolean_expression 是指的数据表中的某一列名吗?
如:
Select(case flag
when 0 then "0代表的意义"
when 1 then "1代表的意义"
else "2代表的意义"
end)flag from temp;
但这个例子却是常数“1”啊,这是为什么:
select * from T_D where Issue in
(
select
case 1 when 1 then
(select Issue from T_D where Issue = (select min(Issue) from T_D where Issue > t1.Issue))
end
from T_D as t1 where Issue in (
select Issue from T_D
where (No1=2 and No2=4 and No3=6) or (No1=2 and No2=6 and No3=4) or
(No1=4 and No2=2 and No3=6) or (No1=4 and No2=6 and No3=2) or
(No1=6 and No2=4 and No3=2) or (No1=6 and No2=2 and No3=4)
)
)