Subject | Re: [firebird-support] Re: SQL aging report |
---|---|
Author | Arno Brinkman |
Post date | 2003-08-27T14:57:40Z |
Hi,
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 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 = 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
btw, isn't COMPANY unneeded in the sub-selects ?
SELECT
c1.CO_NAME,
(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
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
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 s2
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
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81
> > Does it return the correct results now?Ooops, wrong alias, should be :
> >
> 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 = 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/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
btw, isn't COMPANY unneeded in the sub-selects ?
SELECT
c1.CO_NAME,
(SELECT SUM(s2.SA_TOTAL) FROM SALESREG s2
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
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 s2
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
Regards,
Arno Brinkman
ABVisie
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/
Nederlandse firebird nieuwsgroep :
news://80.126.130.81