这个WHERE子句添加到查询中是什么?

时间:2018-11-26 18:41:45

标签: sql

我试图更好地理解以下查询的答案:https://www.w3resource.com/sql-exercises/sql-subqueries-exercise-22.php

答案是:

SELECT 
    departments.department_id, result1.total_amt 
FROM 
    departments,  
    (SELECT employees.department_id, SUM(employees.salary) total_amt  
     FROM employees  
     GROUP BY department_id) result1 
WHERE 
    result1.department_id = departments.department_id;

但是,我不明白为什么我需要最后一部分:

WHERE result1.department_id = departments.department_id

0 个答案:

没有答案