请教一条数据库T-SQL语句,简单的判别语句,就是不知道啊
有表:employee
属性为:name salary(工资)
现在要求把工资大于10000的定义为高工资,低于的叫低工资。
并且输出名字和工资,以及工资分类。要求用T-SQL语句。应该是IF..Else...的吗??
++++++++++++++++
use Company
declare @vstr varchar(10)
if(select salary from employee) <30000
begin
set @vstr= '低工资 '
end
else if(select salary from employee) <50000
begin
set @vstr= '中等工资 '
end
else
begin
set @vstr= '高工资 '
end
select name,salary,@vstr from employee;
++++++++++++++++++++++++++++++++++++++++++
这么写不对啊,应该怎么做??
[解决办法]
select name,salary,case when salary <30000 then '低工资 '
when salary between 30000 and 50000 then '中等工资 '
else '高工资 ' end as '工资分类 '
from employee
[解决办法]
這麼寫
Select
name,
salary,
(Case When salary <30000 Then '低工资 '
Else Case When salary <50000 Then '中等工资 '
Else '高工资 ' End
End) As 工资分类
From
employee
[解决办法]
select name,salary,case when salary <10000 then '低工资 '
else '高工资 ' end as 工资分类
from employee
[解决办法]
declare @tb table([name] varchar(10),salary decimal(10,2))
insert into @tb select 'liu ',10000
union all select 'zhen ',20000
union all select 'li ',8000
union all select 'yang ',25000
select [name],salary,salary,case when salary> 10000 then 'high ' else 'low ' end as grade
from @tb
[解决办法]
楼主不要把简单的问题想复杂了,凡尽量往简单的方面想,没错的。。
我的异常网推荐解决方案:软件开发者薪资,http://www.myexception.cn/other/1391128.html