[firebase-br] Sql Maluca
Antonio Pires
delphi em irati.com.br
Sáb Mar 4 00:09:08 -03 2006
SELECT CodiProd, SUM(QuanProd) as Qtda from NotaItem
where Data between '01.01.2005' and '03.03.2006' and UnidProd = 'KG'
Group by CodiProd
Order By Qtda Desc, CodiProd
Retorna:
1 - 49
2 - 21
6 - 10
3 - 5
4 - 5
5 - 1
SELECT CodiProd, SUM(QuanProd) as Qtda from OrcaItem
where Data between '01.01.2005' and '03.03.2006' and UnidProd = 'KG'
Group by CodiProd
order by Qtda Desc, CodiProd
Retorna:
2 - 10
6 - 10
1 - 2
SELECT CodiProd, SUM(QuanProd) as Qtda from NotaItem
where Data between '01.01.2005' and '03.03.2006' and UnidProd = 'KG'
Group by CodiProd
Union All
SELECT CodiProd, SUM(QuanProd) as Qtda from OrcaItem
where Data between '01.01.2005' and '03.03.2006' and UnidProd = 'KG'
Group by CodiProd
order by Qtda Desc, CodiProd
Retorna:
1 - 49
2 - 21
2 - 10
6 - 10
6 - 10
3 - 5
4 - 5
1 - 2
5 - 1
o que eu desejo é o seguinte:
1 - 49
2 - 31
6 - 20
3 - 5
4 - 5
1 - 2
5 - 1
o que estou errando ????
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.1.1/273 - Release Date: 02/03/2006
Mais detalhes sobre a lista de discussão lista