Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL help needed - popular combination problem

Author  Topic 

noclist
Starting Member

4 Posts

Posted - 2007-10-28 : 13:12:45
For a class, I need to write SQL statements for an assortment of problems and I'm stuck on the last few:

What is the most popular combination of 2 products that are ordered simultaneously? The most popular combination is defined as follows: Consider any combination of two products such as (LS200A, ATM50A). Looking at all orders, count the number of times these two products were present in an order. An order could of course have other products in it than just these two, so you are not limited to examining only orders with exactly two products. If you repeat this process for all possible combinations of two products, then that combination which was present the highest number of times in all orders is the most popular combination of two products that were ordered simultaneously. The quantities ordered are not relevant in this context.

The result of the query should look something like the following:

First Product ----- Second Product ------ Max Number of Times
--- LS200A --------- ATM50A ------------------- 7 -----------

I know little to no SQL, just the basics of it and my professor is pretty terrible at teaching it. I'm thinking I'll need to make a virtual table with a CREATE VIEW but I'm not sure where to go after that. I also need to write statements for the most popular combination of three products. If anyone could give me a hand, I would really appreciate it. Thanks a lot.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-28 : 15:32:42
Duplicate post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=91707



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -