Subject RE: [ib-support] Sum as last record in query result?
Author Amrita Chaudhury
You can either use a stored proc to do the queries if the queries are kind
of predefined,
or,
You can do a select 1, 1,1, sum(A.field2 * B.fieldY) as Total
from table1 A
left outer join table 2 B on A.field3=B.fieldZ
group by .....


-----Original Message-----
From: Joe Martinez [mailto:joe@...]
Sent: Tuesday, August 27, 2002 3:27 PM
To: Interbase Support
Subject: [ib-support] Sum as last record in query result?



I'm constructing a query as follows:

select A.field1, A.field2, B.fieldX, B.fieldY, A.field2 * B.fieldY as
Total
from table1 A
left outer join table 2 B on A.field3=B.fieldZ

Ok. That's fine.

Now, I want to add one more row to the end of the result, that has the
first 4 fields blank/null, and the last column be the sum of the Total
column from the above query.

I figured that I could do it with a UNION. I can create a second query:

select sum(A.field2 * B.fieldY) as Total
from table1 A
left outer join table 2 B on A.field3=B.fieldZ

The problem is that this only returns one column, and you can't do a
UNION unless both Selects return the same number of columns. I can't
just pick 4 other fields because then I'd have to do a Group By, and
those columns would have different values, and I'd get more than one
row.

Can anyone think of a way to do this?

The reason that I need to do this, is that I'm feeding the result into a
report generator that only allows one query, so I need the individual
values and the sum to come out as the result of a single query.

-Joe


To unsubscribe from this group, send an email to:
ib-support-unsubscribe@egroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .




[Non-text portions of this message have been removed]