Subject Re: SQL aging report
Author dixonepperson
> Ooops, wrong alias, should be :
>
I came up with this, and I think its working right, I am going to
compare it with your statement. But next question, is this the most
efficient way to do this type of query?

SELECT s1.SA_CUSTID, c1.CO_NAME,

(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
WHERE (s2.SA_INVDATE BETWEEN '8/20/2003' AND '8/27/2003' AND
s2.SA_CUSTID=s1.SA_CUSTID)
GROUP BY s2.SA_CUSTID),

(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
WHERE (s2.SA_INVDATE BETWEEN '8/15/2003' AND '8/20/2003' AND
s2.SA_CUSTID=s1.SA_CUSTID)
GROUP BY s2.SA_CUSTID),

(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
WHERE (s2.SA_INVDATE BETWEEN '8/11/2003' AND '8/14/2003' AND
s2.SA_CUSTID=s1.SA_CUSTID)
GROUP BY s2.SA_CUSTID)

FROM SALESREG s1 LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID=c1.CO_IDNUM)

Thanx Dixon