在单个查询中按总和和总和分组 [英] Getting group by sum and total sum in a single query
本文介绍了在单个查询中按总和和总和分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在单个查询中按类别和所有产品的总价获取所有产品的总价.
Is there any way to get total price of all products by category and total price of all products in a single query.
下面是查询,我正在使用按类别给出价格.
Below is query i am using giving price by category.
SELECT SUM(price) as totalprice
FROM products
Group BY category_id
推荐答案
使用 ROLLUP 与您的查询.
GROUP BY子句允许使用WITH ROLLUP
修饰符,从而将多余的行添加到摘要输出中.
The GROUP BY clause permits a WITH ROLLUP
modifier that causes extra rows to be added to the summary output.
SELECT category_id,SUM(price) as totalprice
FROM products
GROUP BY category_id WITH ROLLUP
这篇关于在单个查询中按总和和总和分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文