SQL中case when then的使用
在mapper.xml文件中,需要直接给查询的数据直接赋值或者别名显示的时候需要用到 CASE WHEN THEN select
简单case函数(推荐)
- CASE xxx WHEN ‘x’ THEN ‘x’ WHEN ‘x’ THEN ‘x’ ELSE ‘xx’ END
case搜索函数
- CASE WHEN xxx = ‘x’ THEN ‘x’ WHEN xxx = ‘x’ THEN ‘x’ ELSE ‘xx’ END
扩展
select case
when total > max then 2
when total < min then 1
else 0
end
from ta
update
UPDATE table SET xxx =(
CASE
WHEN xxx > xx THEN 'xx'
WHEN xxx > xx THEN 'xx'
ELSE 'xx'
END )
WHERE y = 'a';