包含两个 SELECTS 的 UNION 的查询,其中包含 LOCATION_ID、STREET_ADDRESS、CITY、COUNTRY_NAME 和“部门编号”列。结果必须是所有位置的列表,其中包含该位置的部门数。该列表必须按部门数量从多到少的顺序排列。
SELECT locations.location_id,
locations.street_address,
locations.city,
locations.country_id
FROM locations,departments
WHERE (locations.location_id = departments.location_id)
GROUP BY locations.location_id,
locations.street_address,
locations.city,
locations.country_id
UNION ALL
SELECT Count(departments.department_name)
FROM departments
WHERE (locations.location_id = departments.location_id)
GROUP BY departments.department_id, departments.location_id
ORDER BY (departments.department_name) DESC;`