我希望在不使用total
的情况下获得专栏的group by clause
,因为我不想concat
任何字符串。
我正在寻找这种期望的结果:
| customer id | project name | Product Name | Quantity | price | total |
+--------------+--------------+--------------+----------+--------+----------+
| 9 | xyz | ppn | 2 | 2 | 4 |
+--------------+--------------+--------------+----------+--------+----------+
| 11 | pqr | xxx | 2 | 2 | 4 |
+--------------+--------------+--------------+----------+--------+----------+
| | | | | | 8 |<=== Grand total
+---------------------------------------------------------------------------+
这里是SQL小提琴:http://sqlfiddle.com/#!9/30fdd5/2
答案 0 :(得分:3)
我认为这可以满足您的需求:
positive
要100%清楚总计是结果集中的最后一行,请添加SELECT customer_id, project_name, product_name, quantity,
price, quantity * price as total
FROM project_expenses_data
UNION ALL
SELECT NULL, NULL, NULL, NULL, NULL, sum(quantity * price)
FROM project_expenses_data;
子句。