Subject Re: SQL aging report
Author dixonepperson
> SELECT
> c1.CO_NAME,
> (SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
> LEFT JOIN COMPANY c ON (s2.SA_CUSTID = c.CO_IDNUM)
> WHERE (s2.SA_INVDATE BETWEEN '8/21/2003' AND '8/27/2003') AND
> s2.SA_CUSTID = c1.CO_IDNUM),
> (SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
> LEFT JOIN COMPANY c ON (s2.SA_CUSTID = c.CO_IDNUM)
> WHERE (s2.SA_INVDATE BETWEEN '8/15/2003' AND '8/20/2003') AND
> s2.SA_CUSTID = c1.CO_IDNUM),
> (SELECT SUM(s2.SA_TOTAL) FROM SALESREG
> LEFT JOIN COMPANY c ON (s2.SA_CUSTID = c.CO_IDNUM)
> WHERE (s2.SA_INVDATE BETWEEN '8/11/2003' AND '8/14/2003') AND
> s2.SA_CUSTID = c1.CO_IDNUM)
> FROM
> SALESREG s1
> LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID = c1.CO_IDNUM)
> GROUP BY
> c1.CO_NAME,
> c1.CO_IDNUM
>
> Note! Maybe i forgot a alias somewhere !
>
> Does it return the correct results now?
>
> Regards,
> Arno

I changed it to this, but its still the wrong result. Like I am
getting the totals for all customers in F_2 and F_3

SELECT
c1.CO_NAME,
(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2 LEFT JOIN COMPANY c ON
(s2.SA_CUSTID = c.CO_IDNUM)
WHERE (s2.SA_INVDATE BETWEEN '8/21/2003' AND '8/27/2003') AND
s2.SA_CUSTID = c1.CO_IDNUM),

(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2 LEFT JOIN COMPANY c ON
(s2.SA_CUSTID = c.CO_IDNUM)
WHERE (s2.SA_INVDATE BETWEEN '8/15/2003' AND '8/20/2003') AND
s2.SA_CUSTID = c.CO_IDNUM),

(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2 LEFT JOIN COMPANY c ON
(s2.SA_CUSTID = c.CO_IDNUM)
WHERE (s2.SA_INVDATE BETWEEN '8/11/2003' AND '8/14/2003') AND
s2.SA_CUSTID = c.CO_IDNUM)

FROM SALESREG s1 LEFT JOIN COMPANY c1 ON (s1.SA_CUSTID = c1.CO_IDNUM)
GROUP BY
c1.CO_NAME, c1.CO_IDNUM