diff --git a/models/world_wb_mides/empenho.sql b/models/world_wb_mides/empenho.sql index c0f93667..b62ec070 100644 --- a/models/world_wb_mides/empenho.sql +++ b/models/world_wb_mides/empenho.sql @@ -64,13 +64,13 @@ WITH empenhado_ce AS ( SAFE_CAST (codigo_projeto_atividade AS STRING) AS acao, SAFE_CAST (codigo_elemento_despesa AS STRING) AS modalidade_despesa, ROUND(SAFE_CAST (valor_empenhado AS FLOAT64),2) AS valor_inicial, - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_ce e + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_ce e ), anulacao_ce AS ( SELECT SAFE_CAST (CONCAT(numero_empenho, ' ', TRIM(codigo_orgao), ' ', TRIM(codigo_unidade), ' ', geoibgeId, ' ', (SUBSTRING(data_emissao_empenho,6,2)), ' ', (SUBSTRING(data_emissao_empenho,3,2))) AS STRING) AS id_empenho_bd, ROUND(SUM(SAFE_CAST (valor_anulacao AS FLOAT64)),2) AS valor_anulacao - FROM basedosdados-dev.world_wb_mides_staging.raw_anulacao_ce + FROM basedosdados-staging.world_wb_mides_staging.raw_anulacao_ce GROUP BY 1 ), frequencia_ce AS ( @@ -137,7 +137,7 @@ empenhado_mg AS ( ROUND(SAFE_CAST (IFNULL(valor_anulacao,0) AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (valor_empenho_original AS FLOAT64) + SAFE_CAST (IFNULL(valor_reforco,0) AS FLOAT64) - SAFE_CAST (IFNULL(valor_anulacao,0) AS FLOAT64),2) AS valor_final - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_mg + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_mg ), dlic AS ( SELECT @@ -233,17 +233,17 @@ empenhado_mg AS ( END, cd_elemento) AS elemento_despesa, SAFE_CAST (vl_Empenho AS FLOAT64) AS valor_inicial - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_pb e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pb m ON e.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_funcao f ON e.de_Funcao = f.nome_funcao - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_subfuncao sf ON e.de_Subfuncao = sf.nome_subfuncao + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_pb e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pb m ON e.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_funcao f ON e.de_Funcao = f.nome_funcao + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_subfuncao sf ON e.de_Subfuncao = sf.nome_subfuncao ), anulacao_pb AS ( SELECT SAFE_CAST (CONCAT(nu_Empenho, ' ', a.cd_ugestora, ' ', m.id_municipio, ' ', (RIGHT(dt_Ano,2))) AS STRING) AS id_empenho_bd, SUM(SAFE_CAST (vl_Estorno AS FLOAT64)) AS valor_anulacao - FROM basedosdados-dev.world_wb_mides_staging.raw_estorno_pb a - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pb m ON a.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) + FROM basedosdados-staging.world_wb_mides_staging.raw_estorno_pb a + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pb m ON a.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) GROUP BY 1 ), frequencia_pb AS ( @@ -433,10 +433,10 @@ empenhado_mg AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (VALOREMPENHADO AS FLOAT64),2) AS valor_final - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_pe e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pe m ON e.NOMEUNIDADEGESTORA = m.NOMEUNIDADEGESTORA - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_funcao` fun ON UPPER(TRIM(REPLACE(REPLACE(e.FUNCAO, 'Encargos Especias', 'Encargos Especiais'), 'Assistêncial Social', 'Assistência Social'))) = UPPER(nome_funcao) - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_subfuncao` sub ON UPPER(TRIM(e.SUBFUNCAO)) = UPPER(nome_subfuncao) + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_pe e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pe m ON e.NOMEUNIDADEGESTORA = m.NOMEUNIDADEGESTORA + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_funcao` fun ON UPPER(TRIM(REPLACE(REPLACE(e.FUNCAO, 'Encargos Especias', 'Encargos Especiais'), 'Assistêncial Social', 'Assistência Social'))) = UPPER(nome_funcao) + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_subfuncao` sub ON UPPER(TRIM(e.SUBFUNCAO)) = UPPER(nome_subfuncao) ), empenho_pr AS ( SELECT @@ -465,7 +465,7 @@ empenhado_mg AS ( ROUND(SAFE_CAST (vlEstornoEmpenho AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (vlEmpenho AS FLOAT64) - IFNULL(SAFE_CAST (vlEstornoEmpenho AS FLOAT64),0),2) AS valor_final - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_pr e + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_pr e LEFT JOIN basedosdados.br_bd_diretorios_brasil.municipio m ON e.cdIBGE = m.id_municipio_6 ), empenhado_rs AS ( @@ -492,8 +492,8 @@ empenhado_mg AS ( SAFE_CAST(cd_projeto AS STRING) AS acao, SAFE_CAST(REPLACE(cd_elemento, '.','') AS STRING) AS elemento_despesa, SAFE_CAST(vl_empenho AS FLOAT64) AS valor_inicial - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao = 'E' AND (SAFE_CAST(vl_empenho AS FLOAT64) >= 0) GROUP BY 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 @@ -509,8 +509,8 @@ empenhado_mg AS ( SELECT SAFE_CAST(CONCAT(nr_empenho, ' ', c.cd_orgao, ' ', m.id_municipio, ' ', (RIGHT(ano_empenho,2))) AS STRING) AS id_empenho_bd, -1*SUM(SAFE_CAST(vl_empenho AS FLOAT64)) AS valor_anulacao - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao='E' AND (SAFE_CAST(vl_empenho AS FLOAT64) < 0) GROUP BY 1 @@ -667,10 +667,10 @@ empenhado_mg AS ( SAFE_CAST (cd_acao AS STRING) AS acao, SAFE_CAST ((LEFT(ds_elemento,8)) AS STRING) AS elemento_despesa, SAFE_CAST (REPLACE(vl_despesa, ',', '.') AS FLOAT64) AS valor_inicial - FROM basedosdados-dev.world_wb_mides_staging.raw_despesa_sp e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) + FROM basedosdados-staging.world_wb_mides_staging.raw_despesa_sp e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) WHERE tp_despesa = 'Empenhado' ), frequencia_sp AS ( @@ -683,8 +683,8 @@ empenhado_mg AS ( SELECT SAFE_CAST (CONCAT(LEFT(nr_empenho, LENGTH(nr_empenho) - 5), ' ', codigo_orgao, ' ', id_municipio, ' ', (RIGHT(ano_exercicio,2))) AS STRING) AS id_empenho_bd, SUM(SAFE_CAST (REPLACE(vl_despesa, ',', '.') AS FLOAT64)) AS valor_anulacao - FROM basedosdados-dev.world_wb_mides_staging.raw_despesa_sp a - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = a.ds_orgao + FROM basedosdados-staging.world_wb_mides_staging.raw_despesa_sp a + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = a.ds_orgao WHERE tp_despesa = 'Anulação' GROUP BY 1 ), @@ -692,8 +692,8 @@ empenhado_mg AS ( SELECT SAFE_CAST (CONCAT(LEFT(nr_empenho, LENGTH(nr_empenho) - 5), ' ', codigo_orgao, ' ', id_municipio, ' ', (RIGHT(ano_exercicio,2))) AS STRING) AS id_empenho_bd, SUM(SAFE_CAST (REPLACE(vl_despesa, ',', '.') AS FLOAT64)) AS valor_reforco - FROM basedosdados-dev.world_wb_mides_staging.raw_despesa_sp r - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = r.ds_orgao + FROM basedosdados-staging.world_wb_mides_staging.raw_despesa_sp r + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = r.ds_orgao WHERE tp_despesa = 'Reforço' GROUP BY 1 ), diff --git a/models/world_wb_mides/liquidacao.sql b/models/world_wb_mides/liquidacao.sql index 79507a74..5b5baee6 100644 --- a/models/world_wb_mides/liquidacao.sql +++ b/models/world_wb_mides/liquidacao.sql @@ -58,8 +58,8 @@ WITH liquidacao_ce AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (valor_liquidado AS FLOAT64),2) AS valor_final, - FROM basedosdados-dev.world_wb_mides_staging.raw_liquidacao_ce l - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_ce m ON l.codigo_municipio = m.codigo_municipio + FROM basedosdados-staging.world_wb_mides_staging.raw_liquidacao_ce l + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_ce m ON l.codigo_municipio = m.codigo_municipio ), liquidacao_mg AS ( SELECT @@ -87,8 +87,8 @@ WITH liquidacao_ce AS ( ROUND(SAFE_CAST (valor_anulado AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (valor_liquidacao_original AS FLOAT64) - IFNULL(SAFE_CAST (valor_anulado AS FLOAT64),0),2) AS valor_final - FROM basedosdados-dev.world_wb_mides_staging.raw_liquidacao_mg AS l - LEFT JOIN basedosdados-dev.world_wb_mides_staging.raw_rsp_mg AS r ON l.id_rsp=r.id_rsp + FROM basedosdados-staging.world_wb_mides_staging.raw_liquidacao_mg AS l + LEFT JOIN basedosdados-staging.world_wb_mides_staging.raw_rsp_mg AS r ON l.id_rsp=r.id_rsp ), liquidacao_pb AS ( SELECT @@ -112,8 +112,8 @@ WITH liquidacao_ce AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (vl_Liquidacao AS FLOAT64),2) AS valor_final, - FROM basedosdados-dev.world_wb_mides_staging.raw_liquidacao_pb l - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pb m ON l.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) + FROM basedosdados-staging.world_wb_mides_staging.raw_liquidacao_pb l + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pb m ON l.cd_ugestora = SAFE_CAST(m.id_unidade_gestora AS STRING) ), liquidacao_pr AS ( SELECT @@ -137,9 +137,9 @@ WITH liquidacao_ce AS ( ROUND(SAFE_CAST (vlLiquidacaoEstornado AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (vlLiquidacaoLiquido AS FLOAT64),2) AS valor_final, - FROM basedosdados-dev.world_wb_mides_staging.raw_liquidacao_pr l + FROM basedosdados-staging.world_wb_mides_staging.raw_liquidacao_pr l LEFT JOIN basedosdados.br_bd_diretorios_brasil.municipio m ON cdIBGE = id_municipio_6 - LEFT JOIN basedosdados-dev.world_wb_mides_staging.raw_empenho_pr e ON l.idEmpenho = e.idEmpenho + LEFT JOIN basedosdados-staging.world_wb_mides_staging.raw_empenho_pr e ON l.idEmpenho = e.idEmpenho ), liquidacao_pe AS ( SELECT @@ -163,8 +163,8 @@ WITH liquidacao_ce AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_anulacao, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (VALOR AS FLOAT64),2) AS valor_final, - FROM basedosdados-dev.world_wb_mides_staging.raw_liquidacao_pe l - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pe m ON l.ID_UNIDADE_GESTORA = SAFE_CAST(m.ID_UNIDADEGESTORA AS STRING) + FROM basedosdados-staging.world_wb_mides_staging.raw_liquidacao_pe l + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pe m ON l.ID_UNIDADE_GESTORA = SAFE_CAST(m.ID_UNIDADEGESTORA AS STRING) ), liquidado_rs AS ( SELECT @@ -186,8 +186,8 @@ WITH liquidacao_ce AS ( SAFE_CAST (NULL AS STRING) AS documento_responsavel, SAFE_CAST (NULL AS BOOL) AS indicador_restos_pagar, SAFE_CAST(vl_liquidacao AS FLOAT64) AS valor_inicial - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao = 'L' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) >= 0) GROUP BY 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 @@ -196,8 +196,8 @@ WITH liquidacao_ce AS ( SELECT SAFE_CAST(CONCAT(nr_empenho, ' ', c.cd_orgao, ' ', m.id_municipio, ' ', (RIGHT(ano_empenho,2))) AS STRING) AS id_empenho_bd, -1*SUM(SAFE_CAST(vl_liquidacao AS FLOAT64)) AS valor_anulacao - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao = 'L' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) < 0) GROUP BY 1 @@ -306,10 +306,10 @@ WITH liquidacao_ce AS ( SAFE_CAST (cd_acao AS STRING) AS acao, SAFE_CAST ((LEFT(ds_elemento,8)) AS STRING) AS elemento_despesa, SAFE_CAST (REPLACE(vl_despesa, ',', '.') AS FLOAT64) AS valor_inicial - FROM basedosdados-dev.world_wb_mides_staging.raw_despesa_sp e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) + FROM basedosdados-staging.world_wb_mides_staging.raw_despesa_sp e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) WHERE tp_despesa = 'Valor Liquidado' ), frequencia AS ( diff --git a/models/world_wb_mides/pagamento.sql b/models/world_wb_mides/pagamento.sql index 231661e5..946f4281 100644 --- a/models/world_wb_mides/pagamento.sql +++ b/models/world_wb_mides/pagamento.sql @@ -47,8 +47,8 @@ WITH empenho_ce AS ( SAFE_CAST (nome_negociante AS STRING) AS nome_credor, SAFE_CAST (REPLACE (REPLACE (numero_documento_negociante, '.',''), '-','') AS STRING) AS documento_credor, SAFE_CAST (SAFE_CAST (codigo_fonte_ AS INT64) AS STRING) AS fonte, - FROM basedosdados-dev.world_wb_mides_staging.raw_empenho_ce e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_ce m ON e.codigo_municipio = m.codigo_municipio + FROM basedosdados-staging.world_wb_mides_staging.raw_empenho_ce e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_ce m ON e.codigo_municipio = m.codigo_municipio ), pago_ce AS ( SELECT @@ -74,8 +74,8 @@ WITH empenho_ce AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (valor_nota_pagamento AS FLOAT64),2) AS valor_final, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_liquido_recebido, - FROM basedosdados-dev.world_wb_mides_staging.raw_pagamento_ce p - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_ce m ON p.codigo_municipio = m.codigo_municipio + FROM basedosdados-staging.world_wb_mides_staging.raw_pagamento_ce p + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_ce m ON p.codigo_municipio = m.codigo_municipio ), frequencia_ce AS ( SELECT @@ -149,8 +149,8 @@ WITH empenho_ce AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (valor_pagamento_original AS FLOAT64) - IFNULL(SAFE_CAST (vlr_anu_fonte AS FLOAT64),0),2) AS valor_final, ROUND(SAFE_CAST (valor_pagamento_original AS FLOAT64) - IFNULL(SAFE_CAST (vlr_anu_fonte AS FLOAT64),0) - IFNULL(SAFE_CAST (vlr_ret_fonte AS FLOAT64),0),2) AS valor_liquido_recebido, - FROM basedosdados-dev.world_wb_mides_staging.raw_pagamento_mg AS p - LEFT JOIN basedosdados-dev.world_wb_mides_staging.raw_rsp_mg AS r ON p.id_rsp=r.id_rsp + FROM basedosdados-staging.world_wb_mides_staging.raw_pagamento_mg AS p + LEFT JOIN basedosdados-staging.world_wb_mides_staging.raw_rsp_mg AS r ON p.id_rsp=r.id_rsp ), pago_pb AS ( SELECT @@ -179,9 +179,9 @@ pago_pb AS ( ROUND(SAFE_CAST (vl_Retencao AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (vl_Pagamento AS FLOAT64),2) AS valor_final, ROUND(SAFE_CAST (vl_Pagamento AS FLOAT64) - SAFE_CAST (vl_Retencao AS FLOAT64),2) AS valor_liquido_recebido, - FROM basedosdados-dev.world_wb_mides_staging.raw_pagamento_pb p - LEFT JOIN basedosdados-dev.world_wb_mides_staging.raw_empenho_pb e ON p.nu_Empenho = e.nu_Empenho AND p.cd_UGestora = e.cd_ugestora AND p.de_UOrcamentaria = e.de_UOrcamentaria AND p.dt_Ano = e.dt_Ano - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pb m ON SAFE_CAST(e.cd_ugestora AS STRING) = SAFE_CAST(m.id_unidade_gestora AS STRING) + FROM basedosdados-staging.world_wb_mides_staging.raw_pagamento_pb p + LEFT JOIN basedosdados-staging.world_wb_mides_staging.raw_empenho_pb e ON p.nu_Empenho = e.nu_Empenho AND p.cd_UGestora = e.cd_ugestora AND p.de_UOrcamentaria = e.de_UOrcamentaria AND p.dt_Ano = e.dt_Ano + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pb m ON SAFE_CAST(e.cd_ugestora AS STRING) = SAFE_CAST(m.id_unidade_gestora AS STRING) ), frequencia_pb AS ( SELECT id_pagamento_bd, COUNT (id_pagamento_bd) frequencia_id FROM pago_pb @@ -244,8 +244,8 @@ pago_pb AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND((CASE WHEN (SAFE_CAST ((VALOR) AS FLOAT64) < -1000000000000) THEN NULL ELSE SAFE_CAST ((VALOR) AS FLOAT64) END),2) AS valor_final, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_liquido_recebido, - FROM basedosdados-dev.world_wb_mides_staging.raw_pagamento_pe p - INNER JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_pe m ON SAFE_CAST(p.ID_UNIDADE_GESTORA AS STRING) = SAFE_CAST(m.ID_UNIDADEGESTORA AS STRING) + FROM basedosdados-staging.world_wb_mides_staging.raw_pagamento_pe p + INNER JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_pe m ON SAFE_CAST(p.ID_UNIDADE_GESTORA AS STRING) = SAFE_CAST(m.ID_UNIDADEGESTORA AS STRING) ), pagamento_pr AS ( SELECT @@ -274,8 +274,8 @@ pago_pb AS ( ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_ajuste, ROUND(SAFE_CAST (p.cdIBGE AS FLOAT64),2) AS valor_final, ROUND(SAFE_CAST (0 AS FLOAT64),2) AS valor_liquido_recebido, - FROM basedosdados-dev.world_wb_mides_staging.raw_pagamento_pr p - LEFT JOIN basedosdados-dev.world_wb_mides_staging.raw_empenho_pr e ON p.idEmpenho = e.idEmpenho + FROM basedosdados-staging.world_wb_mides_staging.raw_pagamento_pr p + LEFT JOIN basedosdados-staging.world_wb_mides_staging.raw_empenho_pr e ON p.idEmpenho = e.idEmpenho LEFT JOIN basedosdados.br_bd_diretorios_brasil.municipio m ON e.cdIBGE = id_municipio_6 ), pago_rs AS ( @@ -302,8 +302,8 @@ pago_pb AS ( SAFE_CAST (NULL AS BOOL) AS indicador_restos_pagar, SAFE_CAST (NULL AS STRING) AS fonte, SAFE_CAST(vl_pagamento AS FLOAT64) AS valor_inicial - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) >= 0) GROUP BY 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 @@ -312,8 +312,8 @@ pago_pb AS ( SELECT SAFE_CAST(CONCAT(nr_empenho, ' ', c.cd_orgao, ' ', m.id_municipio, ' ', (RIGHT(ano_empenho,2))) AS STRING) AS id_empenho_bd, -1*SUM(SAFE_CAST(vl_pagamento AS FLOAT64)) AS valor_anulacao - FROM `basedosdados-dev.world_wb_mides_staging.raw_despesa_rs` AS c - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao + FROM `basedosdados-staging.world_wb_mides_staging.raw_despesa_rs` AS c + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_orgao_rs` AS a ON c.cd_orgao = a.cd_orgao LEFT JOIN `basedosdados.br_bd_diretorios_brasil.municipio` m ON m.id_municipio = a.id_municipio WHERE tipo_operacao = 'P' AND (SAFE_CAST(vl_liquidacao AS FLOAT64) < 0) GROUP BY 1 @@ -477,10 +477,10 @@ pago_pb AS ( SAFE_CAST (cd_acao AS STRING) AS acao, SAFE_CAST ((LEFT(ds_elemento,8)) AS STRING) AS elemento_despesa, SAFE_CAST (REPLACE(vl_despesa, ',', '.') AS FLOAT64) AS valor_inicial - FROM basedosdados-dev.world_wb_mides_staging.raw_despesa_sp e - LEFT JOIN basedosdados-dev.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) - LEFT JOIN `basedosdados-dev.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) + FROM basedosdados-staging.world_wb_mides_staging.raw_despesa_sp e + LEFT JOIN basedosdados-staging.world_wb_mides_staging.aux_municipio_sp m ON m.ds_orgao = e.ds_orgao + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_funcao` ON ds_funcao_governo = UPPER(nome_funcao) + LEFT JOIN `basedosdados-staging.world_wb_mides_staging.aux_subfuncao` ON ds_subfuncao_governo = UPPER(nome_subfuncao) ), frequencia AS ( SELECT id_empenho_bd, COUNT (id_empenho_bd) AS frequencia_id