如何在汇总或汇总函数等方面进行汇总?
ROUND(SUM(T.TICKET_PRICE),2)
例如:
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH ROLLUP
答案 0 :(得分:0)
我能想到的最好的事情是 -
SELECT EmpId, Yr,
CASE WHEN EmpId IS NULL AND Yr IS NULL
THEN ROUND(SUM(Sales))
ELSE SUM(Sales)
END AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH ROLLUP
不幸的是,如果EmpId
和Yr
为NOT NULL
,这只会有效。
答案 1 :(得分:0)
将汇总放在子查询中:
SELECT R.EmpID, R.Yr, ROUND(R.Sales,2) AS Sales
FROM (
SELECT EmpId, Yr, SUM(Sales) AS Sales
FROM Sales
GROUP BY EmpId, Yr WITH ROLLUP) R
答案 2 :(得分:0)
你是如此接近,只需用圆函数包装你的总和。
SELECT EmpId, Yr, round(SUM(Sales),2) AS Sales
FROM Sales
GROUP BY EmpId, Yr