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 ) = ‘低薪'
当做一个列就好了
使用 if 与 else if 进行判断吧case 不允许动态添加(比如使用for循环,遍历1-9的值,你只能手动写 case 1 case 2 ... ... )
如果实在想用,你得把所有的情况在 case 里写全了;
再者说了,判断条件与此条件执行结果不固定,为什么不把对应关系写在数据库里,或者配置文件里,这样不是更方便吗,否则一直改源码,谁遭得住....
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)