October 6, 2008 at 8:52 pm
zypsy (10/6/2008)
Based on some criteria, I have reduced the number of orders in the datasetfrom about 42000 to about 6000.
Then, methinks that something is drastically wrong... you just said (and I agree), that most customers will buy one thing in any given day. According to your stats, that's an average of 7 things per day.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 6, 2008 at 11:50 pm
sorry, if i've confused you.
customers can and do have multiple items in an order. but customers won't have more than one order in a day.
the data reduction has been done by removing orders that are buybacks/exchanges, and orders that have a single item.
October 7, 2008 at 5:16 am
zypsy (10/6/2008)
i have got the table i want by running something likeSELECT billdate,custcode,custname,
MAX(CASE WHEN Seq=1 THEN brand ELSE NULL END) AS brand,
MAX(CASE WHEN Seq=1 THEN item ELSE NULL END) AS item,
MAX(CASE WHEN Seq=1 THEN cat ELSE NULL END) AS cat,
MAX(CASE WHEN Seq=2 THEN brand ELSE NULL END) AS brand2,
MAX(CASE WHEN Seq=2 THEN item ELSE NULL END) AS item2,
.
.
.
FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY billdate,custcode,custname
ORDER BY billdate,custcode,custname) AS Seq, *
FROM MyTable)t
GROUP BY billdate,custcode,custname
You're on the right track with that. The only concern I have is the assumed maximum of 5 items per customer per "day". As soon as you assume that, someone else will buy 9 or 10.
Since you can't get the test data we actually need to test code with, I'll see if I can make some so that it's all handled dynamically without regard to the number of purchase by a given customer on a given day... if you think you need it. Lemme know, please.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply