我运行了SELECT
语句来查询这些结果。我想知道如何SUM
总计“已售数量”。怎么做?
结果:
当前,这是查询:
SELECT
"CustomerName",
"Completed Date",
"System Size" AS 'Quantity Sold',
(NOW() -INTERVAL 26 DAY) AS 'Pay Period Start Date',
(NOW() -INTERVAL 13 DAY) AS 'Pay Period End Date',
(SELECT SUM("System Size") FROM Deals) AS 'System Size Installed'
FROM Deals
然后我有第二个Excel报告,需要在所述付款期间手动输入“总费用”。关于如何自动执行此步骤的任何想法?
答案 0 :(得分:0)
SELECT
"CustomerName",
DATE("Completed Date") AS "Completed Date",
SUM("System Size") AS "Quantity Sold",
(NOW() -INTERVAL 26 DAY) AS "Pay Period Start Date",
(NOW() -INTERVAL 13 DAY) AS "Pay Period End Date",
(SELECT SUM("System Size") FROM Deals) AS "System Size Installed"
FROM
Deals
GROUP BY
"CustomerName",
DATE("Completed Date")
ORDER BY
"CustomerName",
DATE("Completed Date")
使用DATE()
仅是为了“以防万一”,您的列还包括该值的时间部分,但确实假定它不是字符串列。
此外,我强烈建议不要在列名称中使用空格。您不会在变量名称中使用空格,因此请勿在SQL列名称中使用空格...