| WebSys Fall 2003 |
|   WebSys Home   |   WebSys Blog |
Tables users, products and cartentries on monte (via phpMyAdmin).
Joe's shopping cart, just the product name, quantity, price and item totals:
SELECT products.name,
cartentries.quantity,
products.price,
(quantity * price) AS itemtotal
FROM `cartentries` , users, products
WHERE cartentries.uid = users.uid
AND users.username = 'joe' AND
cartentries.pid = products.pid
Each user name, number of items and total price of shopping cart, ordered by the price:
SELECT users.username, count( products.pid )
AS pcount, sum( quantity * price )
AS ptot FROM `cartentries` , users, products
WHERE cartentries.uid = users.uid AND cartentries.pid = products.pid
GROUP BY (cartentries.uid)
ORDER BY ptot