0

列 LOCATION_ID、STREET_ADDRESS、CITY、COUNTRY_NAME および "No of Depts" を含む 2 つの SELECT の UNION を含むクエリ。結果は、その場所の部門数を含むすべての場所のリストである必要があります。リストは、部門の数が多いものから少ないものの順に並べる必要があります。

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;`
4

1 に答える 1