Created
November 14, 2020 18:34
-
-
Save fabio-stein/38e20cb14ae150104172026cfb8aac19 to your computer and use it in GitHub Desktop.
Exercicio 2 SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH bichos_familia AS( | |
SELECT m.id_familia, SUM(m.quantidadebichosestimacao) AS bichos FROM Morador m | |
GROUP BY m.id_familia | |
) | |
SELECT c.bairro AS 'Bairro', COALESCE(SUM(b.bichos),0) AS 'Bichos de Estimação' FROM Condominio c | |
LEFT JOIN Familia f ON c.Id = f.id_condominio | |
LEFT JOIN bichos_familia b ON b.id_familia = f.id | |
GROUP BY c.bairro |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment