这是我的疑问:
SELECT customers.state, SUM( orders.quantity * items.unitcost ) AS 'value of orders'
FROM customers, items, orders
WHERE customers.custID = orders.custID
AND orders.itemID = items.itemID
GROUP BY customers.state
LIMIT 0 , 50
它有什么问题吗?它给出了看起来可能正确的答案,但是当手动检查时,其中一些只是一点点关闭(没有一个表有超过五十行)。这对我来说似乎很奇怪,我无法弄清楚我做错了什么。
答案 0 :(得分:2)
希望这会有所帮助::
SELECT
customers.state, SUM( orders.quantity * items.unitcost ) AS 'value of orders'
FROM
customers
inner join orders on (customers.custID = orders.custID)
inner join items on (orders.itemID = items.itemID),
GROUP BY customers.state
LIMIT 0 , 50