使用 UNION ALL 从两个查询中获取结果,但它正在丢失一行数据。如果我切换哪个选择语句首先出现,则丢失的数据会切换到不同的行。我知道每个 slect 语句在单独运行时都会提取正确的信息,但放在一起时不能正常工作。以下是我的查询:
SELECT YEAR( orderDate ) AS "SalesYear"
, MONTH( orderDate ) AS "SalesMonth"
, SUM( orderTotal ) AS "TotalSales"
, orderDetails.productID
FROM orders
INNER JOIN orderdetails
ON orders.orderID = orderDetails.orderID
INNER JOIN products
ON orderDetails.productID = products.productID
UNION ALL
SELECT YEAR( orderDate ) AS "SalesYear"
, MONTH( orderDate ) AS "SalesMonth"
, SUM( orderTotal ) AS "TotalSales"
, instorepurchasedetails.productID
FROM in_storepurchase
INNER JOIN instorepurchasedetails
ON in_storepurchase.isPurchaseID = instorepurchasedetails.isPurchaseID
INNER JOIN products
ON instorepurchasedetails.productID = products.productID
GROUP BY YEAR(orderDate ), MONTH( orderDate ), orderTotal, productID
任何想法为什么会发生这种情况以及我能做什么?