我需要一个两个不同的值相同的列,但在不同的日期范围,这是我正在做的
SELECT `sales-store-id`,
((SUM (`gen-acute-sales-after-returns`) AS `totalGenericSales` ,
(SUM(`eth-acute-sales-after-returns`) AS `totalEthicalSales`,
SUM(`sales-after-returns`) AS `totalSales` WHERE `date-s` BETWEEN '2018-11-01' AND '2018-11-12')
AND
((SUM (`gen-acute-sales-after-returns`)) AS `totalGenericSalesPM` ,
(SUM(`eth-acute-sales-after-returns`)) AS `totalEthicalSalesPM`,
SUM(`sales-after-returns`) AS `totalSalesPM`
FROM `sales` WHERE `date-s` BETWEEN '2018-10-01' AND '2018-10-12')
GROUP BY`sales-store-id`
它是工作时,为单一日期范围,但添加多个日期范围后,它给出语法错误
2条答案
按热度按时间3pmvbmvn1#
使用union all对不同日期范围的子查询进行分组可以实现这一点。
snz8szmq2#
您可以尝试使用条件聚合