G
Guillermo_Lopez
Hello all,
I am trying to calculate the average sales for each SKU while removing
the x% of the sales as outliers.
So from 30k rows in the sales table with about 2,000 SKUs, this is the
query that I currently have. It works correctly; however, it takes too
long to run. What I want is a query or several queries that run
faster.
SELECT Q1.PRODUCT, Q1.Invoice, Q1.UNITS INTO ProductInvoiceNoOutliers
FROM Q204_1_Sales_Detail AS Q1
WHERE (((Q1.Invoice) Not In (SELECT top 5 PERCENT Q2.Invoice FROM
Q204_1_Sales_Detail AS Q2 WHERE Q2.PRODUCT=Q1.PRODUCT ORDER BY
Q2.UNITS DESC));
Then: SELECT Product, Avg(Units) as AVGUNITS FROM Query GROUP BY
Product
Like I was saying, this query works but not as fast as I want it too.
For 30k rows, it takes more than 10 hours to run. I need to drop it
down to minutes or less if possible. Is there any other way?
VBA code is acceptable.
Thanks in Advanced
- GL
I am trying to calculate the average sales for each SKU while removing
the x% of the sales as outliers.
So from 30k rows in the sales table with about 2,000 SKUs, this is the
query that I currently have. It works correctly; however, it takes too
long to run. What I want is a query or several queries that run
faster.
SELECT Q1.PRODUCT, Q1.Invoice, Q1.UNITS INTO ProductInvoiceNoOutliers
FROM Q204_1_Sales_Detail AS Q1
WHERE (((Q1.Invoice) Not In (SELECT top 5 PERCENT Q2.Invoice FROM
Q204_1_Sales_Detail AS Q2 WHERE Q2.PRODUCT=Q1.PRODUCT ORDER BY
Q2.UNITS DESC));
Then: SELECT Product, Avg(Units) as AVGUNITS FROM Query GROUP BY
Product
Like I was saying, this query works but not as fast as I want it too.
For 30k rows, it takes more than 10 hours to run. I need to drop it
down to minutes or less if possible. Is there any other way?
VBA code is acceptable.
Thanks in Advanced
- GL