CREATE
VIEW VIEW_SPED_C190
AS

select 
	NFEC.ID, 
	NFED.CST_ICMS, 
	NFED.CFOP, 
	NFED.ALIQUOTA_ICMS, 
	NFEC.DATA_HORA_EMISSAO,
	SUM(NFED.VALOR_TOTAL) AS SOMA_VALOR_OPERACAO, 
	SUM(NFED.BASE_CALCULO_ICMS) AS SOMA_BASE_CALCULO_ICMS, 
	SUM(NFED.VALOR_ICMS) AS SOMA_VALOR_ICMS,
	SUM(NFED.VALOR_BASE_CALCULO_ICMS_ST) AS SOMA_BASE_CALCULO_ICMS_ST, 
	SUM(NFED.VALOR_ICMS_ST) AS SOMA_VALOR_ICMS_ST,
	SUM(NFED.VALOR_OUTRAS_DESPESAS) AS SOMA_VL_RED_BC,
	SUM(NFED.VALOR_IPI) AS SOMA_VALOR_IPI
from 
	VIEW_SPED_NFE_DETALHE NFED
	INNER JOIN NFE_CABECALHO NFEC ON (NFED.ID_NFE_CABECALHO = NFEC.ID)
group by 
	ID, CST_ICMS, CFOP, ALIQUOTA_ICMS, DATA_HORA_EMISSAO