![]() |
|
Archives of the TeradataForumMessage Posted: Wed, 26 Jan 2011 @ 15:35:24 GMT
Why do I need to filter the data to improve query performance? The SALES_DATA table, updated weekly, contains sales data for each item at each location. The query is to get total sales ($) and quantity by week for each item. The desired result is to get a rolling 53 weeks of aggregate sales and quantity. The query below works, but is very slow, approximately 47 minutes.
SELECT S.ITEM_NBR
, S.YR_WK
, SUM(S.WKLY_SALES) AS WKLY_SALES
, SUM(S.WKLY_QTY) AS WKLY_QTY
FROM DB_NAME.SALES_DATA S
,(SELECT YR_WK
FROM DB_NAME.CALENDAR_DAY
WHERE GREGORIAN_DATE = DATE - 379)C
WHERE S.YR_WK > C.YR_WK
GROUP BY 1,2
However, when I put a filter on the SALES_DATA table, the response time improves to 4 minutes **Note** The YR_WK 10939 is week 39 of 2009 and is just an arbitrary week that falls outside of the desired result.
SELECT S.ITEM_NBR
, S.YR_WK
, SUM(S.WKLY_SALES) AS WKLY_SALES
, SUM(S.WKLY_QTY) AS WKLY_QTY
FROM DB_NAME.SALES_DATA S
,(SELECT YR_WK
FROM DB_NAME.CALENDAR_DAY
WHERE GREGORIAN_DATE = DATE - 379)C
WHERE S.YR_WK > 10939
AND S.YR_WK > C.YR_WK
Why is this filter necessary to improve performance? Terry Clear GRS Project Manager
| ||||||||||||||||||||||||||||||||||||||||||||||||
| | ||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright 2016 - All Rights Reserved | ||||||||||||||||||||||||||||||||||||||||||||||||
| Last Modified: 15 Jun 2023 | ||||||||||||||||||||||||||||||||||||||||||||||||