答案 0 :(得分:1)
尝试您的原始查询,但最后不要使用WITH ROLLUP-听起来您实际上并不需要汇总,只是分组
答案 1 :(得分:0)
也许这对您有用:
SELECT
CustomerID,Cashier,
OrderDate,
SUM(Total) as totalprice
FROM
SalesandReports
GROUP BY
OrderDate,
CustomerID,
Cashier
WITH ROLLUP
首先通过设置Orderdate,group by
将首先按照它进行处理,然后再根据客户编号和收银员进行操作。
答案 2 :(得分:0)
您可以在这里做个窍门:
SELECT
max(CustomerID) as CustomerId,
max(Cashier) as Cashier,
coalsce(OrderDate,'Other Dates'),
SUM(Total) as totalprice
FROM
SalesandReports
GROUP BY
OrderDate WITH ROLLUP
通过此GROUP BY
,只能由OrderDate完成。
参考:堆栈溢出问题 Select multiple columns from a table, but group by one 的答案。
答案 3 :(得分:0)
试试我的朋友
SELECT
CustomerID
,Cashier
, OrderDate
,SUM(ISNULL(totalprice,0)) as totalprice
FROM SalesandReports
WHERE OrderDate is not NULL
GROUP BY CustomerID, Cashier, OrderDate