Voici ma requête complexe :
SELECT IDRegion, Pays, SUM(COLA) As Equipement_Auto, SUM(COLB) As Equipement_Soudure, SUM(COLC) As Equipement_Garage, SUM(COLD) As Retail_DIY, SUM(COLE) As Teleshopping, SUM(COLF) As Branded, SUM(COLG) AS Outillage_Electrique, SUM(COLH) AS Constructeur_Automobile, SUM(COLI) AS Autre FROM (SELECT Pays.IDRegion, Pays.Pays, COUNT(*) AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 1 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLA FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 1 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays) UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, COUNT(*) AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 2 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLB FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 2 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, COUNT(*) AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 3 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLC FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 3 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, COUNT(*) AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 4 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLD FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 4 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, COUNT(*) AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 5 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLE FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 5 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, COUNT(*) AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 6 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLF FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 6 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, COUNT(*) AS COLG, 0 AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 7 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLG FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 7 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, COUNT(*) AS COLH, 0 AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 8 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLH FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 8 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, COUNT(*) AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 9 GROUP BY Pays.IDRegion, Pays.Pays UNION (SELECT Pays.IDRegion, Pays.Pays, 0 AS COLA, 0 AS COLB, 0 AS COLC, 0 AS COLD, 0 AS COLE, 0 AS COLF, 0 AS COLG, 0 AS COLH, 0 AS COLI FROM pays WHERE Pays.Pays NOT IN( SELECT Pays.Pays, COUNT(*) AS COLI FROM Personne_morale INNER JOIN Type_Personne_morale ON Personne_morale.IDPersonne_morale = Type_Personne_morale.IDPersonne_morale, Pays INNER JOIN Personne_morale ON Pays.IDPays = Personne_morale.IDPays WHERE Type_Personne_morale.IDType = 9 GROUP BY Pays.Pays) GROUP BY Pays.IDRegion, Pays.Pays))))))))))))))))) GROUP BY IDRegion, Pays |