sql语句中case when的使用问题

select case t.dl when '0000' then t.tdl='未分类' else t.tdl=t.tdl end, t.tdl lx from table1 t
就是要根据t.dl的值改变t.tdl的值的问题

第1个回答  推荐于2018-11-27
举个例子就明白了,例如在员工的工资表把员工的工资分成等级
1000以下为低薪,1000-2000为中等,其他为高薪
select (case when salary <= 1000 then '低薪' when salary > 1000 and salary < 2000 then '中等' else '高薪' end ) as 工资等级 from employee
这样,工资等级就可以当做一个列来处理,包括where里面,可以写where (case when salary <= 1000 then '低薪' when salary > 1000 and salary < 2000 then '中等' else '高薪' end ) = ‘低薪'
当做一个列就好了本回答被提问者和网友采纳
相似回答