我正在努力计算具有SUM的查询的SUM。这是我的疑问:
SELECT rs.resellerid
,r.company
,r.insidesales
,SUM(total_reseller_sales) as TotalResellerSalesYear
FROM sales_report_resellers rs
INNER JOIN resellers r
ON rs.resellerid = r.resellerid
WHERE (sid > '282' AND sid < '292')
AND r.insidesales = 1
GROUP BY rs.resellerid, r.company, r.insidesales
查询返回5条记录,每条记录金额为1美元。我需要所有5条记录的SUM。
答案 0 :(得分:1)
从Group By
列表
Select
和非聚合列
SELECT SUM(total_reseller_sales) as Total
FROM sales_report_resellers rs
INNER JOIN resellers r
ON rs.resellerid = r.resellerid
WHERE (sid > '282' AND sid < '292')
AND r.insidesales = 1
答案 1 :(得分:0)
如果没有看到示例数据集,我猜您需要从SELECT
和GROUP BY
中删除转销广告。
SELECT
[r].[company]
,[r].[insidesales]
,SUM([total_reseller_sales]) AS [TotalResellerSalesYear]
FROM
[sales_report_resellers] [rs]
INNER JOIN [resellers] [r] ON [rs].[resellerid] = [r].[resellerid]
WHERE
(
[sid] > '282'
AND [sid] < '292'
)
AND [r].[insidesales] = 1
GROUP BY
[r].[company]
,[r].[insidesales];