1.单值判断,相当于switch case
CASE expression
WHEN value1 THEN returnvalue1
WHEN value2 THEN returnvalue2
WHEN value3 THEN returnvalue3
ELSE defaultreturnvalue
END
例子SELECT
SELECT FName,
(CASE FLevel WHEN 1 THEN 'VIP客户'
WHEN 2 THEN '高级客户'
WHEN 3 THEN '普通客户'
ELSE '客户类型错误'
END) as FLevelName
FROM T_Customer
2.相当于if…else…else….
CASE
WHEN condition1 THEN returnvalue1
WHEN condition 2 THEN returnvalue2
WHEN condition 3 THEN returnvalue3
ELSE defaultreturnvalue
END
例子:
SELECT FName, FWeight,
(CASE
WHEN FWeight<40 THEN ‘瘦瘦'
WHEN FWeight>50 THEN ‘肥肥'
ELSE 'ok'
END) as isnormal
FROM T_Person