嘿,我正在努力解决一个问题,我是数据库管理的初学者。我有以下数据库,我想进行以下查询:List the locations the company has employees located at以及每个位置的员工数量是多少来自最多员工的位置 有人请帮忙!
这是数据库
答案 0 :(得分:0)
我相信这会得到你正在寻找的东西。
Select l.location_id, c.country_name, count(e.employee_id) as employee_count
From locations l
left join countries c ON c.country_id = l.country_id
left join departments d ON l.location_id = d.location_id
left join employees e ON e.manager_id = d.manager_id
GROUP BY l.location_id, c.country_name
ORDER BY employee_count DESC;