SQL查询语句(sql server),查询员工收入水平
发布网友
发布时间:2022-04-11 06:41
我来回答
共5个回答
热心网友
时间:2022-04-11 08:10
别听楼上几个乱扯,这个问题是case只能写一个,when可以写多个
SELECT Name AS 姓名,Address AS 住址,
CASE
WHEN(SELECT InCome FROM Salary
WHERE Salary.EmployeeID=Employees.EmployeeID)<2000 THEN '低收入'
------CASE
WHEN (SELECT InCome FROM Salary
WHERE Salary.EmployeeID=Employees.EmployeeID)BETWEEN 2000 AND 3000 THEN '中等收入'
ELSE '高收入'
END AS 收入水平
FROM Employees
热心网友
时间:2022-04-11 09:28
--如下这个应该是最合适的:
SELECT a.Name AS 姓名,a.Address AS 住址,
CASE
WHEN isnull(b.InCome,0) < 2000 THEN '低收入'
WHEN isnull(b.InCome,0) BETWEEN 2000 AND 3000 THEN '中等收入'
ELSE '高收入'
END AS 收入水平
FROM Employees a inner join Salary b
where
a.EmployeeID=b.EmployeeID
热心网友
时间:2022-04-11 11:03
你没有加括号啊,下面是我修改的
SELECT Name AS 姓名,Address AS 住址,
(CASE
WHEN(SELECT InCome FROM Salary
WHERE Salary.EmployeeID=Employees.EmployeeID)<2000 THEN '低收入' END),
(CASE
WHEN (SELECT InCome FROM Salary
WHERE Salary.EmployeeID=Employees.EmployeeID)BETWEEN 2000 AND 3000 THEN '中等收入' END),
(CASE WHEN (SELECT InCome FROM Salary
WHERE Salary.EmployeeID=Employees.EmployeeID)>3000 THEN'高收入'END) AS 收入水平
FROM Employees
ELSE那部分我也不会,我不确定CASE语句里面是不是能用ELSE,所以写了三个CASE,而且按照你的思路修改后显示的结果最后有三列分别是"无列名""无列名""收入水平"
你看出来了吧,就是说只有最后一个AS了收入水平.
热心网友
时间:2022-04-11 12:54
SELECT Name AS 姓名,Address AS 住址,
CASE
WHEN InCome<2000 THEN '低收入'
CASE
WHEN InCome BETWEEN 2000 AND 3000 THEN '中等收入'
ELSE '高收入'
END AS 收入水平
FROM Employees, Salary
where
Salary.EmployeeID=Employees.EmployeeID
热心网友
时间:2022-04-11 15:02
语法貌似没有错误,我看了你写在这上门的()后面没有留空格 是不是因为这个问题?