Subject | Re: How to make my report quicker |
---|---|
Author | heroes3lover |
Post date | 2007-05-23T03:33:54Z |
So many nice guys here,
The SQL is very simple:
SELECT s.PLU, s.DESCRIPTION,
CAST( 'N' AS VARCHAR(1) ) AS ISLINKED,
CAST( '-1' AS VARCHAR(10) ) AS STOREID,
SUM(A.QUANTITYSOLD*s.PACKQTY) AS QUANTITY,
SUM(B.QUANTITYSOLD*s.PACKQTY) AS PROMQUANTITY,
SUM(D.QUANTITYSOLD*s.PACKQTY) AS PURCHQUANTITY,
SUM(A.SALESEXGST) AS SALES,
SUM(A.SALESEXGST-A.COSTEXGST) AS SALESPROFIT,
SUM(B.SALESEXGST) AS PROMSALES,
SUM(B.SALESEXGST-B.COSTEXGST) AS PROMPROFIT,
SUM(D.COSTEXGST) AS PURCHSALES
FROM PLUWEEK A
JOIN STDPROD s ON (s.PLU = A.PLU )
and( A.SALESDATE BETWEEN :STARTDATE AND :ENDDATE)
and(A.STOREID=:THESTOREID)
JOIN FILTERSTD F
ON( S.PLU= F.CODE1 )
AND( F.FILTERID = :THEFILTERID )
LEFT OUTER JOIN PRMPLUWEEK b ON (A.STOREID=B.STOREID) AND
(A.SALESDATE=B.SALESDATE) AND (A.PLU=B.PLU)
LEFT OUTER JOIN PURPLUWEEK D ON (A.STOREID=d.STOREID) AND
(A.SALESDATE=d.SALESDATE) AND (A.PLU=D.PLU)
group by S.PLU, S.DESCRIPTION
and the PLAN is:
PLAN SORT (JOIN (JOIN (JOIN (A INDEX (RDB$PRIMARY39),F INDEX
(RDB$PRIMARY535),S INDEX (RDB$PRIMARY152)),B INDEX (RDB$PRIMARY42)),D
INDEX (RDB$PRIMARY45)))
STDPROD keeps all the products information and PLU is primary key,
PRMPLUWEEK and PURPLUWEEK also have primary key storeid/plu/salesdate
maybe 50,000 products in the list.
Thanks,
Roc
The SQL is very simple:
SELECT s.PLU, s.DESCRIPTION,
CAST( 'N' AS VARCHAR(1) ) AS ISLINKED,
CAST( '-1' AS VARCHAR(10) ) AS STOREID,
SUM(A.QUANTITYSOLD*s.PACKQTY) AS QUANTITY,
SUM(B.QUANTITYSOLD*s.PACKQTY) AS PROMQUANTITY,
SUM(D.QUANTITYSOLD*s.PACKQTY) AS PURCHQUANTITY,
SUM(A.SALESEXGST) AS SALES,
SUM(A.SALESEXGST-A.COSTEXGST) AS SALESPROFIT,
SUM(B.SALESEXGST) AS PROMSALES,
SUM(B.SALESEXGST-B.COSTEXGST) AS PROMPROFIT,
SUM(D.COSTEXGST) AS PURCHSALES
FROM PLUWEEK A
JOIN STDPROD s ON (s.PLU = A.PLU )
and( A.SALESDATE BETWEEN :STARTDATE AND :ENDDATE)
and(A.STOREID=:THESTOREID)
JOIN FILTERSTD F
ON( S.PLU= F.CODE1 )
AND( F.FILTERID = :THEFILTERID )
LEFT OUTER JOIN PRMPLUWEEK b ON (A.STOREID=B.STOREID) AND
(A.SALESDATE=B.SALESDATE) AND (A.PLU=B.PLU)
LEFT OUTER JOIN PURPLUWEEK D ON (A.STOREID=d.STOREID) AND
(A.SALESDATE=d.SALESDATE) AND (A.PLU=D.PLU)
group by S.PLU, S.DESCRIPTION
and the PLAN is:
PLAN SORT (JOIN (JOIN (JOIN (A INDEX (RDB$PRIMARY39),F INDEX
(RDB$PRIMARY535),S INDEX (RDB$PRIMARY152)),B INDEX (RDB$PRIMARY42)),D
INDEX (RDB$PRIMARY45)))
STDPROD keeps all the products information and PLU is primary key,
PRMPLUWEEK and PURPLUWEEK also have primary key storeid/plu/salesdate
maybe 50,000 products in the list.
Thanks,
Roc