Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

diegohamaz1

Somar agrupamento MYSQL

Recommended Posts

Galera seguinte tenho a seguitne query

SELECT 

DATE_FORMAT(nf.data,"%Y-%m") AS data_nota,
sum(nf.valor_total/100) AS valor_nota,
sum(nf.volume_total) AS volume_nota,
UPPER(rel_nf.residuo_nome) AS residuo_nome,

	(SELECT 
	sum(nf.valor_total/100)
	FROM `notas_fiscais` AS `nf`
	INNER JOIN `rel_notas_fiscais` AS `rel_nf` ON `nf`.`id` = `rel_nf`.`id_nf`
	where
	   `nf`.`id_gerador` = 10 
	   and `nf`.`excluido` = 0 
	   and `rel_nf`.`excluido` = 0 
	   and `rel_nf`.`reciclavel` = 1 
	   and DATE_FORMAT(nf.data,"%Y-%m") between '2016-07' and '2016-07' 
	group by DATE_FORMAT(nf.data,"%Y-%m")) as total_nota ,

	(SELECT 
	sum(nf.volume_total)
	FROM `notas_fiscais` AS `nf`
	INNER JOIN `rel_notas_fiscais` AS `rel_nf` ON `nf`.`id` = `rel_nf`.`id_nf`
	where
	   `nf`.`id_gerador` = 10 
	   and `nf`.`excluido` = 0 
	   and `rel_nf`.`excluido` = 0 
	   and `rel_nf`.`reciclavel` = 1 
	   and DATE_FORMAT(nf.data,"%Y-%m") between '2016-07' and '2016-07' 
	group by DATE_FORMAT(nf.data,"%Y-%m")) as total_volume 

FROM `notas_fiscais` AS `nf`
INNER JOIN `rel_notas_fiscais` AS `rel_nf` ON `nf`.`id` = `rel_nf`.`id_nf`
LEFT JOIN `rel_residuos` AS `rel_resi` ON `rel_nf`.`id_residuo` = `rel_resi`.`id_residuo`
where
   `nf`.`id_gerador` = 10 
   and `nf`.`excluido` = 0 
   and `rel_nf`.`excluido` = 0 
   and `rel_nf`.`reciclavel` = 1 
   and DATE_FORMAT(nf.data,"%Y-%m") between '2016-07' and '2016-07' 
group by rel_nf.id_residuo
order by rel_nf.residuo_nome

Que me retorna

"data_nota" "valor_nota" "volume_nota" "residuo_nome" "total_nota" "total_volume"
"2016-07" "24282,0000" "6390000" "ALUMÍNIO" "193850,3000" "543090000"
"2016-07" "701,5000" "350000" "ALUMÍNIO" "193850,3000" "543090000"
"2016-07" "3355,8000" "23970000" "APARAS DE PAPEL MISTO 085" "193850,3000" "543090000"
"2016-07" "130163,9000" "965090000" "APARAS DE PAPEL MISTO 085" "193850,3000" "543090000"
"2016-07" "1849,9000" "14230000" "APARAS DE PAPEL MISTO 085" "193850,3000" "543090000"
"2016-07" "7330,0000" "64980000" "APARAS DE PAPEL MISTO 085" "193850,3000" "543090000"
"2016-07" "2924,9000" "26590000" "APARAS DE PAPEL MISTO 095" "193850,3000" "543090000"
"2016-07" "1582,1000" "12170000" "APARAS DE PAPEL MISTO 095" "193850,3000" "543090000"
"2016-07" "7709,9000" "70090000" "APARAS DE PAPEL MISTO 095" "193850,3000" "543090000"
"2016-07" "3493,5000" "23290000" "APARAS DE PAPEL MISTO 095" "193850,3000" "543090000"
"2016-07" "11045,1000" "20040000" "FILME PLÁSTICO" "193850,3000" "543090000"
"2016-07" "5813,6000" "11180000" "FILME PLÁSTICO" "193850,3000" "543090000"
"2016-07" "12768,0000" "85120000" "PAPELÃO ONDULADO" "193850,3000" "543090000"
"2016-07" "30532,0000" "17960000" "PEAD COLORIDO" "193850,3000" "543090000"
"2016-07" "15640,0000" "9200000" "PEAD COLORIDO" "193850,3000" "543090000"
"2016-07" "25346,0000" "22040000" "PET COLORIDO" "193850,3000" "543090000"
"2016-07" "18260,0000" "18260000" "PET COLORIDO" "193850,3000" "543090000"
"2016-07" "568,0000" "2840000" "PP COLORIDO" "193850,3000" "543090000"
"2016-07" "374,5000" "1070000" "PP COLORIDO" "193850,3000" "543090000"
"2016-07" "3844,4000" "13730000" "SUCATA" "193850,3000" "543090000"
"2016-07" "3217,2000" "22980000" "SUCATA DE VIDRO" "193850,3000" "543090000"
"2016-07" "5555,2000" "19840000" "TETRAPACK" "193850,3000" "543090000"
Eu gostaria de somar os produtos iguais tipo aparas papel misto 085 somar os valores na minha consulta e deixar uma linha só...
Como posso fazer?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.