Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Sum of sum
Tue, Aug 18 2009 6:56 AMPermanent Link

"Eduardo [HPro]"
If I have two tables like below:

Table1
====
Field1
Field2

Table2
====
Field1
Field2

And I need to get a sum of Field2 from both tables

select field1, sum(field2) as tot into memory\m1 from table1
group by field1
union all
select field1, sum(field2) as tot from table2
group by field1
;
select field1,sum(tot) from memory\m1
group by field1

My question: Is there another way to do this ? Or a better way to do this ?

Thanks in advance
Eduardo

Wed, Aug 19 2009 3:59 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eduardo,

<< My question: Is there another way to do this ? Or a better way to do this
? >>

Nope, that's the way to do it. Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Wed, Aug 19 2009 6:44 PMPermanent Link

"Rita"

"Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote in message
news:88377233-EF7C-4FC2-9044-41F31AD239A6@news.elevatesoft.com...
>
> Nope, that's the way to do it. Smiley
>

Not exactly true I like the Smileygrin tho.
I used 2 EHLIB grids on a popup form from a button marked Sum
on my cab app. As Ed is only using 2 fields from both tables even
better. My grid does sums so it was way easy I dont have the code
anymore as its sold. But look at attached pic at the sum on the bottom
line. It should help but then it not SQL but Ed wanted a quicker way
and my way that was always live.
Rita





Attachments: sum.png
Image