Je veux montrer le nom du département et le nombre de départements en dehors de l'Australie.SQL Conditionnement
Le problème est que ce code ci-dessous donne encore un décompte incluant les départements en Australie. (Edit) - c'est plus proche de la solution mais pas encore tout à fait raison. - ne pas retourner le compte correct.
SELECT department_name, COUNT(COUNTRIES.country_id)
FROM DEPARTMENTS, COUNTRIES
JOIN (
SELECT COUNT(COUNTRIES.country_name) AS COUNTRY
FROM COUNTRIES
JOIN DEPT_LOCATIONS ON COUNTRIES.country_id = DEPT_LOCATIONS.country_id
WHERE country_name <> 'Australia'
) AS C ON COUNTRY = c.country
GROUP BY department_name;
Voici le schéma de base de données:
COUNTRIES(country_id, country_name, region)
• Primary key: {country_id}
DEPARTMENTS(department_id, department_name, manager_id)
• Primary key: {department_id }
• Foreign key: [manager_id] ⊆ EMPLOYEES[employee_id]
DEPT_LOCATIONS(department_id, city, country_id)
• Primary key: {department_id, city}
• Foreign key: [department_id] ⊆ DEPARTMENTS[department_id] and
[country_id] ⊆ COUNTRIES[country_id]
EMPLOYEES(employee_id, firstname, lastname, email, phone_no, salary,
department_id)
• Primary key: {employee_id}
• Foreign key: [department_id] ⊆ DEPARTMENTS[department_id]
Put 'department_name <> 'Australie' 'dans la clause WHERE à la place. – jarlh