Getting group by sum and total sum in a single query

前端 未结 2 1785
名媛妹妹
名媛妹妹 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 17:50
    SELECT category_id, SUM(price) as totalprice
    FROM products 
    GROUP BY category_id WITH ROLLUP
    

    Check out the page in the manual

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题