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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Best Cross Selling Items

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-21 : 11:05:17
Tobey writes "I am trying to write a query that will return a list of items and, for each item, the top 5 other items that people also bought if they bought that one.

I can do it using ColdFusion by looping through the list of items and doing a separate query for each item, like so:


Select upc from item inner join shot on shot.shotid=item.shotid where shot.lastbook='Clearance2001' order by upc




SELECT top 4 sum(qty) as thecount, ordersitem.UPC FROM OrdersItem inner join Item on (OrdersItem.UPC=Item.UPC) inner join shot on (item.shotid=shot.shotid) WHERE shot.lastbook='Clearance2001' and item.UPC <> #UPC# and Salehold=0 and Soldout=0 and
OrdersID IN (SELECT OrdersID FROM OrdersItem WHERE UPC = #UPC#)
group by ordersitem.upc order by thecount desc


#upc#, #UPC#, #thecount#;




But surely there is a better, SQL-only way to do it?""
   

- Advertisement -