
November 29th, 2003, 12:41 AM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
n00b: Question on SQL Query w/SUM
n00b to these forums. Hopefully I have found a place where I can get my advanced SQL whipped in to shape. Thanks in advance.
3 tables:
Shopping_Carts
Inventory
Specials
Long and short of it, I want to get a subtotal of the products in the shopping cart. I would like to pull the price from the inventory table if it doesn't exist for that part number in the specials table (meaning it isn't on special).
I am at a loss on where to start with this one. Here is a sample of a plain query I use for just pulling from the inventory table:
SELECT sum(i.price * s.qty) AS total
FROM ShoppingCarts s, Inventory i
WHERE s.hashcode = '#cookie.hashcode#'
AND i.id = s.itemid
As far as I can tell, right now I could only do an outter join on that Specials table and then loop over a query (without the sum) and add up with a IF statement in the loop. I could have easily had that done by now, but I'd really like to learn this stuff. From looking over my Sams SQL in 10 mins book and the SQL Books Online I can't see an answer to my problem.
Thoughts?
|