0
我有這個表基於MySQL中的數量獲取SUM?
訂單
- orders_id
- order_article_id
- order_invoice_id
- order_customer_id
- order_qty
ARTICLES
- articles_id
- ARTICLE_NAME
- article_qty
- article_price
- article_amount
客戶
- customers_id
- CUSTOMER_NAME
- customer_position
- customer_office
和SQL連接表
$sql="SELECT customer_name, article_name, orders_id FROM orders
LEFT JOIN articles ON order_article_id = articles_id
LEFT JOIN customers on order_customer_id = customers_id";
從這個查詢我需要得到金額。 量爲例如
USER:MICHAEL
AMOUNT:ORDER ID = order_article_id + order_qty;
是否有可能在MySQL中做到這一點,或者我需要一些額外的PHP代碼?
不錯,在foreach中查詢什麼? – 2014-09-21 19:36:29
我的查詢返回兩列'customer_name',並將總和重新命名爲'amount' – fthiella 2014-09-21 19:38:29
您可以看看這個http://stackoverflow.com/questions/25963649/getting-sum-and-result-in-several -join桌 – 2014-09-21 20:41:46