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

Home -> Community -> Usenet -> c.d.o.tools -> Cartesian product with totals

Cartesian product with totals

From: Noah <noah.spam.begone_at_rhinocerous.co.uk>
Date: Wed, 18 Jul 2001 11:23:48 +0100
Message-ID: <Vsd57.22768$B5.1704171@monolith.news.easynet.net>

Hello,

I'm trying to get the sum and totals from 2 tables (well, the same table twice, actually) using the below SQL:

SELECT dih.dih_no_post_collection
, dih.dih_total_post_collection
, COUNT(dir.dir_reject_id)
, SUM(dir.dir_amount)
, COUNT(dir2.dir_reject_id)
, NVL(SUM(dir2.dir_amount), 0)

FROM    easygis.dl_invoice_headers  dih

, easygis.dl_invoice_rejects dir
, easygis.dl_invoice_rejects dir2
WHERE dih.dih_header_no = dir.dir_ih_header_no AND dir.dir_rejection_reason != 'No CC line produced' AND dih.dih_cb_trans_batch = 4942 AND dih.dih_header_no = dir2.dir_ih_header_no AND dir2.dir_rejection_reason = 'No CC line produced' GROUP BY dih.dih_no_post_collection
, dih.dih_total_post_collection

It isn't producing the results I require - it's producing a cartesian product on the 2nd set of results. So, if there are 100 rows for the 1st part and 50 rows for the second, the results are dispalyed as 100 and 5000 rows respectively.

Can I get around this in a single SQL statement - at the moment I'm resorting to desperation and doing it as 2 separate ones.

Thanks for any advice,

--
Noah
Remove ".spam.begone"
Received on Wed Jul 18 2001 - 05:23:48 CDT

Original text of this message

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