SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Processing Sales Data against Bundles, Best strategy?


Processing Sales Data against Bundles, Best strategy?

Author
Message
Eichpeel
Eichpeel
Right there with Babe
Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)

Group: General Forum Members
Points: 765 Visits: 257
Hello everyone,
I am trying to find the best way to process incoming sales data against a product / bundle strucuture. I have an idea on how to go about it but it is cumbersome and not very elegant. Plus, I am not sure I am capturing all the scenarios. Anyway, I am pretty sure some of you out there have already been confronted with this task and I am looking into the best way to solve it. Here are the rules:
1. products are bundled together and will be rewarded if all products / quantity from the sales file are matched to a bundle.
2. an instance of a product can only be used against one bundle at a time, meaning we have to keep track of the products as they are used against matching bundles.
3. I need to find the best possible combination of incoming sales data against bundles.
I laid out a simplified structure of the tables below and fake data. Please let me know if you have any additional requirements questions.

-- product table - list of products
declare @product table
(
productid int
,product char(1)
)

-- list of product, the bundle group associated with and the quantity needed to fulfill
-- the bundle requirements
declare @bundle table
(
product int
,bundlegroupid int
,quantity int
)

-- list of bundles and their descriptions
declare @bundlegroup table
(
bundlegroupid int
,bundlegroupdesc nvarchar(25)
,amount int
)

-- sales data
declare @sales table
(
salesid int identity(1,1)
,product char(1)
,quantity int
)

-- insert data into the @product table
insert into @product select 1,'A'
insert into @product select 2,'B'
insert into @product select 3,'C'
insert into @product select 4,'D'
insert into @product select 5,'E'
insert into @product select 5,'F'

-- insert data into the bundle group description
insert into @bundlegroup select 1, 'bundle 1', 25
insert into @bundlegroup select 2, 'bundle 2', 50
insert into @bundlegroup select 3, 'bundle 3', 35

-- insert bundle requirements
insert into @bundle select 1, 1, 1 -- associate product 'A' with 'bundle 1' with a quantity of 1
insert into @bundle select 2, 1, 1 -- associate product 'B' with 'bundle 1' with a quantity of 1

insert into @bundle select 1, 2, 1 -- associate product 'A' with 'bundle 2' with a quantity of 1
insert into @bundle select 3, 2, 1 -- associate product 'C' with 'bundle 2' with a quantity of 1

insert into @bundle select 4, 3, 1 -- associate product 'D' with 'bundle 3' with a quantity of 1
insert into @bundle select 5, 3, 2 -- associate product 'E' with 'bundle 3' with a quantity of 2

-- insert sales data
insert into sales select 'A', 1
insert into sales select 'B', 2
insert into sales select 'C', 1
insert into sales select 'D', 1
insert into sales select 'E', 3
insert into sales select 'F', 1

Thank you.

"Any fool can write code that a computer can understand. Good programmers write
code that humans can understand." -Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
The Dixie Flatline
The Dixie Flatline
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19774 Visits: 6908
Just one question:

Given the sample data you have provided, what do you expect the output to look like?

"Best possible combination" is an unclear requirement. ;-)

Draw us a picture, and we can code it.

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Eichpeel
Eichpeel
Right there with Babe
Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)Right there with Babe (765 reputation)

Group: General Forum Members
Points: 765 Visits: 257
I modified the code sample. I had forgotten about the amount column in the bundle group table, which is the reward amount allocated when a bundle match is found. The requirement was indeed vague without that variable since the best possible total reward amount for the sale is what we are looking for.
The outcome could look like:

salesid product bundleid QuantityIncoming QuantityUsed RewardAmount RewardPick
1 A 1 1 1 25 No
2 B 1 2 1 25 No
1 A 2 1 1 50 Yes
3 C 2 1 1 50 Yes
4 D 3 1 1 35 Yes
5 E 3 3 2 35 Yes
6 F null null null null null

The bundle AC got the RewardPick flag set to 'yes" over the AB bundle because of the greater reward amount. Overall, I am trying to put in place generic code to
1. "find if a combination of products (incoming sales) match any predefined sets of bundles (match by sku and quantity)"
2. After all the possible matches have been found, find the best possible reward outcome across those combinations.

I hope this makes more sense now. I am catching up on reading on permutations / combinations right now Wink since this is first a math problem before being a SQL problem.

Thanks again for looking into it.

"Any fool can write code that a computer can understand. Good programmers write
code that humans can understand." -Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search