SELECT
dcpCode,
dcpLatitude,
dcpLongitude,
SUM((aucPercEnteringUWWTP+coalesce(aucPercC2T,0))*aggGenerated/100) AS habitants_tractats_edar,
uwwPrimaryTreatment,
uwwSecondaryTreatment,
uwwOtherTreatment,
uwwNRemoval,
uwwPRemoval,
uwwUV,
uwwChlorination,
uwwOzonation,
uwwSandFiltration,
uwwMicroFiltration,
uwwOther,
uwwSpecification
FROM
T_DischargePoints,
T_UWWTPAgglos,
T_Agglomerations,
T_UWWTPS
WHERE
T_DischargePoints.dcpState is 1 AND
T_UWWTPS.uwwState is 1 AND
T_UWWTPS.uwwCode = T_DischargePoints.uwwCode AND
T_DischargePoints.uwwCode = T_UWWTPAgglos.aucUwwCode AND
T_Agglomerations.aggCode = T_UWWTPAgglos.aucAggCode
GROUP BY aucUwwCode
ORDER BY
aucUwwCode
;