Show sum at the bottom of column in mysql

前端 未结 2 627
夕颜
夕颜 2021-01-21 04:37

Instead of using the following query to display the sum of a column at the bottom, is there another method than using the Union query

  select amount 
fr         


        
2条回答
  •  伪装坚强ぢ
    2021-01-21 05:10

    The other option is to use SUM() and GROUP BY()

    See: http://dev.mysql.com/doc/refman/5.0/en/group-by-modifiers.html

    SELECT year, SUM(profit) FROM sales GROUP BY year
    

    This gives you yearly profit without a UNION. You can also add conditionals just like in COUNT()

提交回复
热议问题