1
我想一起得到這兩個查詢的結果,但無法弄清楚如何合併它們。目標是按產品獲得每月的總銷售額。我有店內購物和在線訂單。這是第一個查詢,從網上訂單每月獲得的總銷售額:MySQL我可以將這兩個查詢合併在一起嗎?
SELECT YEAR(orderDate) AS "SalesYear"
, MONTH(orderDate) AS "SalesMonth"
, SUM(orderTotal) AS "TotalSales"
, products.productID
FROM orders
INNER JOIN orderdetails ON orders.orderID = orderDetails.orderID
INNER JOIN products ON orderDetails.productID = products.productID
GROUP BY productID, YEAR(orderDate) , MONTH(orderDate)
ORDER BY YEAR(orderDate) , MONTH(orderDate)
下面是從商店購買獲取每月總銷售額按產品查詢:
SELECT YEAR(orderDate) AS "SalesYear"
, MONTH(orderDate) AS "SalesMonth"
, SUM(orderTotal) AS "TotalSales"
, products.productID
FROM in_storepurchase
INNER JOIN instorepurchasedetails
ON in_storepurchase.isPurchaseID = instorepurchasedetails.isPurchaseID
INNER JOIN products
ON instorepurchasedetails.productID = products.productID
GROUP BY productID, YEAR(orderDate) , MONTH(orderDate)
ORDER BY YEAR(orderDate) , MONTH(orderDate)
任何幫助的我如何能夠將這個查詢放入一個查詢中,以便我可以在單個表上獲得所有結果,我們將不勝感激。
OK聽起來愚蠢的,但什麼是靜置的T? – 2013-03-10 19:05:56
謝謝,我明白了。 – 2013-03-10 19:09:38
似乎要放下一行,具體取決於哪個選擇說明最先出現。有任何想法嗎? – 2013-03-10 19:48:09