0

在我的数据库中,我有不同的部门,不同的人分配给他们。我想给每个部门的所有员工加薪 10%,然后把他们加起来,这样我就可以得到每个部门的总工资值。但是,不应列出至少有一名姓氏以“ce”结尾的员工的部门。我有研究、行政和总部部门。只有研究和行政部门应显示其各自的总工资值。

SELECT
dname
, SUM(1.1*salary) AS total_salary 
FROM
employee INNER JOIN department
ON dnumber=dno
WHERE lname NOT LIKE '%ce'
GROUP BY dname
ORDER BY total_salary DESC

这就是我想要的,除了列出所有部门。我怎样才能修改这些语句,以便只显示正确的部门?

4

2 回答 2

1

SELECT dname,
SUM(1.1 * salary) AS total_salary
FROM employee
inner join department
ON dnumber = dno
WHERE dname NOT IN (SELECT dname
FROM departments
INNER JOIN employees
ON dnumber = dno
AND lname NOT LIKE '%ce')
GROUP BY dname
ORDER BY total_salary DESC

于 2013-11-11T08:15:32.883 回答
0
SELECT d2.dname as dept_name, SUM(1.1*e2.salary) AS total_salary 
FROM employee e2
INNER JOIN department d2 ON e2.dnumber=d2.dno and d2.dname not like (
    select distinct(d.dname) as dept_name2 from employees e left join department d on e.dnumber=d.dno where e.lname like '%ce'
    ) as temp
WHERE e2.lname NOT LIKE '%ce'
GROUP BY dept_name
ORDER BY total_salary DESC

假设:
1)department_namedepartment表中代表其名称的列
2)是您想要ResearchAdministration部门的确切名称

于 2013-11-11T08:19:18.357 回答