Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL SUMS?

Re: SQL SUMS?

From: Matthias Gresz <GreMa_at_t-online.de>
Date: 1998/01/29
Message-ID: <6apaab$met$1@news02.btx.dtag.de>#1/1

Hi Ken,

try:

SELECT A.DISTRICT,
       A.SUMBALANCE,
       B.SUMBALANCE

FROM
(SELECT T1.DISTRICT,
       SUM(T1.BALANCE),
	cprno
	FROM
	T1
	GROUP BY
	cprno, district)
	A,
(SELECT 
       SUM(T2.BALANCE),
	T2.cprno
	FROM
	T1
	GROUP BY
	cprno)
	B

WHERE B.CPRNO=A.CPRNO
GROUP BY A.DISTRICT Ken Leach wrote:
>
> Can someone help out with this query?
>
> I have two tables
> T1
> cprno balance district
> 1 100 MA
>
> T2
> transno cprno balance
> 100 1 75
> 101 1 25
>
> As you can see the sum of T2 (should) equal that of the same cprno in T1
>
> I need to have BOTH totals on a sql returned row
>
> SELECT T1.DISTRICT
> SUM(T1.BALANCE)
> SUM(T2.BALANCE)
> FROM T1,T2
> WHERE T1.CPRNO=T2.CPRNO
> GROUP BY T1.DISTRICT
>
> should to return
>
> MA 100 100
>
> but I get
>
> MA 200 100
>
> I HAVE to sum the t1.balance since there could be more than one cprno
> per district.
>
> The problem exists because the t1.balance = 100 is counted twice beause
> the detail has two lines.
>
> how can I properly get the sums?
>
> Thanks..
 
-- 
Regards

Matthias Gresz    :-)
Received on Thu Jan 29 1998 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US