I have a table in PostgreSQL. I would like to count two columns where one has more record than the other. If I use LEFT OUTER JOIN I think it will work, though, I'm not getting with the PostgreSQL syntax. The command I am using is as follows:
SELECT codmunic, ene_ine, count(loc) as energia_ine
from tabela a left join
(SELECT codmunic, COUNT(loc) as energia_ine
FROM tabela
WHERE ene_ine = 's'
GROUP BY codmunic) as ag_caim
using (codmunic)
group by codmunic;