1
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, however, I’m not succeeding with the Postgresql syntax. The command I’m 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;
you just want two columns counting from the same table ?
– Rovann Linhalis
What is the error? There is an example of how you want the data to be returned?
– Camilo Santos
Hello to better evaluate would be nice to post the error that is occurring. group by across the countryside ene_ine
– Everton Heckler
Rovann Linhalis, only two columns... then I do it for the others, that is, I take the codmunic as a base to consult the others.
– Jonatã Paulino
Camilo Santos, this is the error: ERROR: column "ene_ine" does not exist LINE 5: WHERE ene_ine = ’s' HINT: Perhaps you Meant to Reference the column "school census.ener_ine" or the column "a. ener_ine". *********Error ******** ERROR: column "ene_ine" does not exist SQL state: 42703 Hint: Perhaps you Meant to Reference the column "school census.ener_ine" or the column "a. ener_ine". Character: 173
– Jonatã Paulino
Heverton, this is the error: ERROR: column "ene_ine" does not exist LINE 5: WHERE ene_ine = ’s' HINT: Perhaps you Meant to Reference the column "school census.ener_ine" or the column "a. ener_ine". *********Error ******** ERROR: column "ene_ine" does not exist SQL state: 42703 Hint: Perhaps you Meant to Reference the column "school census.ener_ine" or the column "a. ener_ine". Character: 173
– Jonatã Paulino