Empl_Table
的属性:Emp#
(P.K),Emp_Name
,Salary
,Department#
(f.k)
我必须找到结果:
Department#
结果应该是这样的
Department# NameContains'A' TotalSalary
--------------------------------------------
10 2450 8750
20 1110 10875
30 7900 9400
答案 0 :(得分:3)
您想要条件聚合:
select et.department,
sum(case where Name like 'A%' then salary end) as A_salary,
sum(salary) as total_salary
from empl_table et
group by et.department;
答案 1 :(得分:0)
试试这个
SELECT Department#,
Sum(CASE
WHEN ename LIKE 'A%' THEN salary
END) Emp_A_Salary,
Sum(salary) Total_salary
FROM Empl_Table
GROUP BY department#