× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Mike just beat me to it but I will agree with him that using lateral and subqueries will perform better in this case.

The main reason is there should be a lot less work done by limiting size of the datasets requested.


select inv#, tran_date, linetype
, col1A_tot, col2A_tot, col2B_tot
from header as hdr
left join lateral
(select inv#, linetype
, sum(colA) as col1A_tot
, sum(colB) as col1B_tot
from detail1 as dtl1
where hdr.inv# = dtl1.inv#
group by inv#, linetype
) as dtlsum1
on hdr.inv# = dtlsum1.inv#
left join lateral
(select inv#, linetype
, sum(colA) as col2A_tot
, sum(colB) as col2B_tot
from detail2 as dtl2
where hdr.inv# = dtl2.inv#
group by inv#, linetype
) as dtlsum2
on hdr.inv# = dtlsum2.inv#
where
tran_date between '2016-11-01' and '2016-11-30'

Jim


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.