Escolar Documentos
Profissional Documentos
Cultura Documentos
WITH dados AS
(CASE
ELSE 0
i.prod.vprod vprod,
i.prod.vfrete vfrete,
i.prod.vseg vseg,
i.prod.voutro voutro,
i.prod.vdesc vdesc,
i.imposto.icms.resumo.vbc vbc,
i.prod.vprod vicms,
i.prod.ncm ncm,
i.prod.cest cest,
i.prod.extipi extipi,
i.prod.ceantrib ceantrib,
i.prod.cean cean,
n.chave chave,
i._nitem,
c.cd_cnae cnae
FROM nfce.nfce n,
n.procnfe.nfe.infnfe.det i
AND n.mes_emissao = 11
totais AS
(SELECT descricao,
aliq_efetiva,
cean,
ceantrib,
ncm,
cest,
extipi,
cnae,
count(1) qt_itens,
sum(vprod) vprod,
sum(vfrete) vfrete,
sum(vseg) vseg,
sum(voutro) voutro,
sum(vdesc) vdesc,
sum(vbc) vbc,
sum(vicms) vicms,
FROM dados
GROUP BY descricao,
aliq_efetiva,
cean,
ceantrib,
ncm,
cest,
extipi,
cnae),
cruzamento AS
(SELECT t.*,
(CASE
ELSE 0
END) sn_gtin_isento
FROM totais t
LEFT JOIN
FROM teste.gesmed_isentos g
t.ceantrib))
SELECT *
FROM cruzamento
det.item.prod.xprod AS DESCRICAO,
SUM(det.item.prod.vprod) AS total_vprod
FROM
JOIN
JOIN
where
x.nm_reg_apuracao = 'NORMAL'
GROUP BY
det.item.prod.xprod
gessuper_ as (
SELECT
trim(regexp_replace(
regexp_replace(
regexp_replace(
lower(d.descricao),
),
"[\\[\\]']", ""
),
)) AS descricao_limpa,
d.*
FROM
teste.gessuper_aliq_inconsistente d
, nfce_ as (
SELECT
-- a.*,
det.imposto.icms.resumo.picms as aliq_icms,
trim(regexp_replace(
regexp_replace(
regexp_replace(
lower(det.prod.xprod),
),
"[\\[\\]']", ""
),
)) as descricao_limpa,
sum(det.prod.vprod)
where
x.nm_ges = 'GESSUPER'
and a.mes_emissao = 10
SELECT
gessuper_.*,
nfce_.*
FROM gessuper_
JOIN nfce_
ON gessuper_.descricao_limpa = nfce_.descricao_limpa
det.item.prod.ncm AS NCM,
det.item.prod.xprod AS DESCRICAO,
a.procnfe.nfe.infnfe.emit.cnpj as cnpj,
x.cd_cnae as CNAE,
det.imposto.icms.resumo.grupotributacao,
det.imposto.icms.resumo.vicms,
det.imposto.icms.resumo.picms,
det.item.prod.cean as gtin,
x.nm_reg_apuracao
FROM
JOIN
where
x.cd_cnae = 4771701 and a.ano_emissao = 2023 and det.item.prod.ncm LIKE '300%' and
ORDER BY random()
LIMIT 1000000
PESQUISAR ALÍQUOTA
SELECT
SUM(det.item.prod.vprod) as TOTAL_VALOR,
det.imposto.icms.resumo.picms as ALIQ_ICMS
FROM
JOIN
where
GROUP BY
det.imposto.icms.resumo.picms
RELATÓRIO ANALÍTICO
SELECT
a.procnfe.nfe.infnfe.emit.xnome as NOME_EMITENTE,
a.procnfe.nfe.infnfe.emit.cnpj as CNPJ_EMITENTE,
a.procnfe.nfe.infnfe.emit.ie as IE_EMITENTE,
a.procnfe.nfe.infnfe.emit.enderemit.uf as ESTADO_EMITENTE,
a.procnfe.nfe.infnfe.dest.xnome as NOME_DESTINATARIO,
a.procnfe.nfe.infnfe.dest.cnpj as CNPJ_DESTINATARIO,
a.procnfe.nfe.infnfe.dest.im as IE_DESTINATARIO,
a.procnfe.nfe.infnfe.dest.enderDEST.uf as ESTADO_DESTINO,
det.item.prod.ncm AS NCM,
det.item.prod.xprod AS DESCRICAO,
det.item.prod.cfop AS CFOP,
det.item.prod.vprod as VALOR,
det.imposto.icms.resumo.vicms as ICMS,
det.imposto.icms.resumo.picms as ALIQ_ICMS,
a.dia_emissao as DIA,
a.mes_emissao as MES,
a.ano_emissao as ANO
FROM
JOIN
usr_sat_ods.vw_cad_contrib_ccicms x ON x.nu_cnpj = a.procnfe.nfe.infnfe.emit.cnpj
where
GROUP BY
a.procnfe.nfe.infnfe.emit.xnome as NOME_EMITENTE,
a.procnfe.nfe.infnfe.emit.cnpj,
det.item.prod.ncm
RELATÓRIO SINTÉTICO
SELECT
a.procnfe.nfe.infnfe.emit.xnome as NOME_EMITENTE,
a.procnfe.nfe.infnfe.emit.ie as IE_EMITENTE,
a.procnfe.nfe.infnfe.dest.enderDEST.uf as ESTADO_DESTINO,
det.item.prod.ncm AS NCM,
det.item.prod.cfop AS CFOP,
det.item.prod.vprod as VALOR,
det.imposto.icms.resumo.picms as ALIQ_ICMS,
a.ano_emissao as ANO
FROM
JOIN
where
GROUP BY
a.ano_emissao,
a.procnfe.nfe.infnfe.emit.xnome,
a.procnfe.nfe.infnfe.emit.ie,
a.procnfe.nfe.infnfe.dest.enderDEST.uf,
det.item.prod.ncm,
det.item.prod.cfop,
det.item.prod.vprod,
det.imposto.icms.resumo.picms