我正在尝试将总和值向右移动,而不是在底部。
当前,我有此查询:
SELECT
if(product is NULL, 'Total', product) as Product,
total_items as Total,
SUM(total_items) as Subtotal
FROM items
WHERE inv = "ABC"
GROUP BY product
WITH ROLLUP
输出为:
| Product | Total | Subtotal |
| AB | 260 | 260 |
| DE | 66 | 66 |
| Total | 66 | 326 |
有办法我可以这样吗?
| Product | Total | Subtotal |
| AB | 260 | |
| DE | 66 | |
| | | 326 |
好的,我想通了,谢谢您提出的所有建议。我是这样做的
SELECT
product,
total_items as Total,
null as Total
FROM items
WHERE inv = "ABC"
GROUP BY product
UNION ALL
SELECT null, null, Subtotal
FROM
( SELECT
if(product is NULL, 'Subtotal', product) as Product,
SUM(total_items) as Subtotal
FROM items
WHERE inv = "ABC"
GROUP BY product
WITH ROLLUP
) T
WHERE product = "Subtotal"
输出:
| Product | Total | Subtotal |
| AB | 260 | |
| DE | 66 | |
| | | 326 |
:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句