Getting group by sum and total sum in a single query

前端 未结 2 1821
名媛妹妹
名媛妹妹 2020-12-05 17:20

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

2条回答
  •  不知归路
    2020-12-05 18:03

    use ROLLUP with your query.

    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
    

提交回复
热议问题