我想对2列的结果做一个案例。我该怎么做?
e.g:
SELECT CASE amount=100 AND DATE IS NOT NULL WHEN 0 THEN 'Something' ELSE ''
那样的东西?
答案 0 :(得分:10)
select case
when amount = 100 and date is not null then 'something'
else 'something else'
end
这是一个“搜索过的案例表达”(see MSDN):
CASE
WHEN Boolean_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ] END
答案 1 :(得分:4)
select someColumnName,
case
when amount = 100 AND someothercondition then 'XXX'
when amount = 1000 AND anothercondition then 'YYY'
else 'WWW'
end as "MyColumnName"
from myTable
答案 2 :(得分:0)
select
case
when
amount = 100
and date is not null
then
'0'
else
'something else'
end
答案 3 :(得分:0)
寻找SELECT WHEN
答案 4 :(得分:-2)
选择金额= 100且日期不为空的情况,然后选择'某事'其他'某事 当amount = 0时,'something else'以MyColumnName结尾