Skip to content
Snippets Groups Projects
Commit b672b91b authored by lgtg20's avatar lgtg20
Browse files

maybe working

parent 6764b0a5
No related branches found
No related tags found
4 merge requests!449Homologa,!444dev -> hom,!440New indicators,!439Issue 935
......@@ -182,6 +182,16 @@ rqf.addField({
type: 'integer',
field: 'faixa_rendimento_aux_tx'
}
}).addValue({
name: 'age_range_all',
table: 'pnad_novo',
tableField: 'faixa_etaria',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria'
}
}).addValue({
name: 'gender',
table: 'pnad_novo',
......@@ -294,23 +304,24 @@ function matchQueries(queryPartial, queryTotal) {
}
adjustedLiquidFrequency.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
let totalPop = req.sql.clone();
totalPop.field("ano_ref")
.field("faixa_etaria")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.from("pnad_novo")
.group("ano_ref")
.group("faixa_etaria");
adjustedLiquidFrequency.get('/', rqf.parse(), (req, res, next) => {
// Subquery: total_pop
let totalPop = squel.select()
.field("ano_ref")
.field("faixa_etaria")
.field("SUM(peso_domicilio_pessoas_com_cal)", "total")
.from("pnad_novo")
.group("ano_ref")
.group("faixa_etaria");
// Aplicando filtros dinâmicos à subquery total_pop
totalPop = rqf.buildQuery(req, totalPop);
// Subquery: total_apoio_freq
let totalApoioFreq = req.sql.clone();
totalApoioFreq.field("pnad_novo.ano_ref")
.field("pnad_novo.apoio_frequencia_ajustada")
.field("total_pop.total")
let totalApoioFreq = squel.select()
.field("pnad_novo.ano_ref", "ano_ref")
.field("pnad_novo.apoio_frequencia_ajustada", "apoio_frequencia_ajustada")
.field("total_pop.total", "total")
.field("SUM(pnad_novo.peso_domicilio_pessoas_com_cal)", "total_freq")
.from("pnad_novo")
.join(
......@@ -322,15 +333,20 @@ adjustedLiquidFrequency.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
.group("pnad_novo.apoio_frequencia_ajustada")
.group("total_pop.total");
req.sql.field("ano_ref")
.field("apoio_frequencia_ajustada")
.field("round((total_freq / total) * 100,1)", "total")
// Aplicando filtros à subquery total_apoio_freq
totalApoioFreq = rqf.buildQuery(req, totalApoioFreq);
// Query principal
req.sql = squel.select()
.field("total_apoio_freq.ano_ref")
.field("total_apoio_freq.apoio_frequencia_ajustada")
.field("ROUND((total_apoio_freq.total_freq / total_apoio_freq.total) * 100, 1)", "total")
.from(totalApoioFreq, "total_apoio_freq")
.where("ano_ref >= 2019")
.order("ano_ref")
.order("apoio_frequencia_ajustada");
.where("total_apoio_freq.ano_ref >= 2019") // Corrigido para usar alias correto
.order("total_apoio_freq.ano_ref")
.order("total_apoio_freq.apoio_frequencia_ajustada");
next();
next();
}, query, id2str.transform(false), response('adjusted_liquid_frequency'));
module.exports = adjustedLiquidFrequency;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment