473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

"Users shopping for A were also interested in B"

How should I set up a database to be able to efficiently maintain
associations between related items?

Example: Users shopping for Lord Of The Rings trilogy were also
interested in The Hobbit.

There will be many (20000+) items for sale and I need to do this
efficiently, but I don't have an idea how could I do it.

TIA

Jul 23 '05 #1
4 1033
http://www.google.co.uk/groups?selm=...oglegroups.com

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
Yeah but how to create these associations efficiently in the first
place?

Jul 23 '05 #3
This called a relational division, and you can Google it. You want one
with a remainder for doing "shopping baskets".

Having said this, you are better off looking for a data mining tool
that will have the ability to set up the baskets on the fly for
somethign like Amazon.

Assuming you only want to have pairs in the baskets and do this only
once and not on the fly, you can set up a sparse matrix in SQL:

CREATE TABLE Pairs
(item_1_upc CHAR(13) NOT NULL,
item_2_upc CHAR(13) NOT NULL,
tally INTEGER DEFAULT 0 NOT NULL,
CHECK (item_1_upc < item_2_upc) ,
PRIMARY KEY (item_1_upc, item_2_upc));

Now go thru every order, pull out all possible pairs that occur more
than some threshold:

INSERT INTO Pairs(item_1_upc, item_2_upc, tally)
SELECT O1.upc, O2.upc, COUNT(*)
FROM Orders AS O1, Orders AS O2
WHERE O1.order_nbr = O2.order_nbr
AND O1.upc < O2.upc
GROUP BY O1.upc, O2.upc
HAVING COUNT(*) > @some_limit;
From the Pairs matrix, you can then build Triplets with whatever rules

you wish based on the tally. For example, given (a, b, 123) and
(b,c, 100) you know that (a,b,c, ??) cannot have more than 100
occurences, but if I have 1000 b's, the number could be as low as zero.

Jul 23 '05 #4
The first query in the reply I posted does that ("efficiently" is moot
I suppose). If you need something different then please post DDL and
sample data so that we can understand what you need.

In reality, I think most e-tailers would not want to automate the
link-selling process. I suspect the results would be unpredictable and
I doubt that the major sites ever do it that way. Careful review and
selection of the linked products by the sales and marketing team will
probably give a better return.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
0
by: Jonathan Trevor | last post by:
Hi, Spent nearly 8 hours googling and trying code on this yesterday without much success. I'd like to write a .NET application (using .NET primitives, older Win32 calls, or WMI etc) to work out...
2
by: Tim Constantine | last post by:
I have a table "Subscriptions". Subscriptions contains the columns "ChannelID" & "MemberID". The "Channels" table contains a column called "Title" When someone is viewing a channel, I would...
2
by: jwalton | last post by:
I have a web site (for a client) where I am now using a considerable number of XML files. Previously the files were updated off-line, and FTPd to make live. I now need to allow "user editors" to...
6
by: Omey Samaroo | last post by:
Can anyone suggest a practical idea that I can use to "shut-down" users that might still be connected to a database or logged off improperly so I can compact the back-end? Thanks for your...
4
by: seansan | last post by:
Another Q, Because we sometimes need to repair the shared database I would like to find out if there is a way to "kick" all users from a database. The problem is that I cannot repair the...
4
by: belfallas | last post by:
Hi, ive got this problem with one of my databeses. My question is, how do i create a sort of a shopping list on access? Im doing a ficitional pizza shop, and what i want to do is to have an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.