MySQL: Get total in last row of MySql result

前端 未结 6 531
夕颜
夕颜 2020-12-10 04:29

For example I have a table like this:

product | quantity | something
-------------------------------
 abc    |   5      |  2
 xzy    |   5      |  2
 asd             


        
6条回答
  •  忘掉有多难
    2020-12-10 05:14

    You can use rollup to generate totals, but you have to change it to an aggregate function, like this:

    SELECT product, sum(quantity), sum(something)
    FROM tableName
    GROUP BY product WITH ROLLUP
    

提交回复
热议问题