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:02

    (SELECT product, 
            quantity, 
            something 
     FROM   tablename) 
    UNION 
    (SELECT "all"          AS product, 
            SUM(quantity)  AS quantity, 
            SUM(something) AS something 
     FROM   tablename) 
    

    This is working query. It will add a fourth row as desired at the end of your result

提交回复
热议问题