Show sum at the bottom of column in mysql

前端 未结 2 625
夕颜
夕颜 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()

    0 讨论(0)
  • 2021-01-21 05:19

    WITH ROLLUP should perform exactly what you are doing.

    0 讨论(0)
提交回复
热议问题