Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Customer who bought this also bought...
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 27 July 2004 :  12:27:08  Show Profile  Visit D3mon's Homepage
How do the SQL queries for those look?

Do they simply have a list of pre-defined items or is it actually a clever query on the order history?


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 27 July 2004 :  13:43:02  Show Profile  Send ruirib a Yahoo! Message
Never saw one, but sounds simple to me. You could just perform a query to find out other items bought by whoever bought this item as well (it's just a matter of joins) and calculate an aggregate count over those items, just to determine the items to show.

P.S.: Hmmm... don't know if this sounds too clear...


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 27 July 2004 :  17:13:14  Show Profile  Visit D3mon's Homepage
I've a table with unique OrderIDs and another table with unique OrderItemIDs that are linked to the OrderIDs in the first table... while I can mentally picture what needs to happen, I'm not at all sure how to process that into a T-SQL query (although I can usually navigate my way around T-SQL using Selects, Joins, etc.)


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 28 July 2004 :  04:31:47  Show Profile
Here's a copy of the stored procedure from the I Buy Spy shopping cart

CREATE Procedure CustomerAlsoBought
(
    @ProductID int
)
As

/* We want to take the top 5 products contained in
    the orders where someone has purchased the given Product */
SELECT  TOP 5 
    OrderDetails.ProductID,
    Products.ModelName,
    SUM(OrderDetails.Quantity) as TotalNum

FROM    
    OrderDetails
  INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID

WHERE   OrderID IN 
(
    /* This inner query should retrieve all orders that have contained the productID */
    SELECT DISTINCT OrderID 
    FROM OrderDetails
    WHERE ProductID = @ProductID
)
AND OrderDetails.ProductID != @ProductID 

GROUP BY OrderDetails.ProductID, Products.ModelName 

ORDER BY TotalNum DESC

The UK MkIVs Forum
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 28 July 2004 :  12:13:32  Show Profile  Visit D3mon's Homepage
That's splendid David, thanks.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.28 seconds. Powered By: Snitz Forums 2000 Version 3.4.07