Saturday, February 25, 2012

Re-Post Sum of Sum from 2 tables

Thanks, it worked.
Is there a way to add another column to the query that shows the total of 1
column:
pieces volume Pieces Free Volume Free Invoiced TotInvoiced
1 1 0 0 10
50
1 2 0 0 20
50
1 1 0 0 20
50
Thanks in advance
Eric
"Mike Gemmell" <MikeGemmell@.discussions.microsoft.com> wrote in message
news:5D4193EA-C33B-4135-918B-9F78E13907A0@.microsoft.com...
> try
> select sum(QTUM1) as pieces, sum(QTUM2) as volume, sum(QTUM1O) as [Pieces
> free], sum(QTUM2O) as [Volume Free], sum(FATTM) as Invoiced from
> (
> select substring(productcode,1,1) code ,QTUM1, QTUM2, QTUM10, QTUM20,
> FATTM from stat001f where (myYear = 2004 and myMonth = 9)
> union all
> select substring(productcode,1,1) code, QTUM1, QTUM2, QTUM10, QTUM20,
FATTM
> from swstat0f where (myYear = 2004 and myMonth = 9)
> ) x
> group by code
>
> "ericvdb" wrote:
>
tables:
[Pieces
[PiecesTo get what you want you could do the following (there is probably a better
way of doing this though):
select sum(QTUM1) as pieces, sum(QTUM2) as volume, sum(QTUM1O) as [Pieces
free], sum(QTUM2O) as [Volume Free], sum(FATTM) as Invoiced, (select
sum(FATTM) from stat001f where (myYear = 2004 and myMonth = 9) + (select
sum(FATTM) from swstat0f where (myYear = 2004 and myMonth = 9) TotInvoiced
from
(
select substring(productcode,1,1) code ,QTUM1, QTUM2, QTUM10, QTUM20,
FATTM from stat001f where (myYear = 2004 and myMonth = 9)
union all
select substring(productcode,1,1) code, QTUM1, QTUM2, QTUM10, QTUM20, FATTM
from swstat0f where (myYear = 2004 and myMonth = 9)
) x
group by code
"ericvdb" wrote:

> Thanks, it worked.
> Is there a way to add another column to the query that shows the total of
1
> column:
> pieces volume Pieces Free Volume Free Invoiced TotInvoiced
> 1 1 0 0 10
> 50
> 1 2 0 0 20
> 50
> 1 1 0 0 20
> 50
>
> Thanks in advance
> Eric
> "Mike Gemmell" <MikeGemmell@.discussions.microsoft.com> wrote in message
> news:5D4193EA-C33B-4135-918B-9F78E13907A0@.microsoft.com...
> FATTM
> tables:
> [Pieces
> [Pieces
>
>

No comments:

Post a Comment