mysql select sum group by date

前端 未结 6 1544
情歌与酒
情歌与酒 2020-12-02 12:59

Quick question, I have the following table

+-------------+---------------------+
| total       | o_date              |
+-------------+---------------------+
         


        
相关标签:
6条回答
  • 2020-12-02 13:42

    Get Month And Year wise data from MySQL database:

    SELECT MONTHNAME(o_date), YEAR(o_date), SUM(total) 
    FROM the_table 
    GROUP BY YEAR(date), MONTH(date)
    
    0 讨论(0)
  • 2020-12-02 13:42
    SELECT SUM(total)
    FROM table
    GROUP BY MONTH(o_date)
    
    0 讨论(0)
  • 2020-12-02 13:45

    This solution will give you the month name as a column of your resultset, followed by the total as required.

    SELECT MONTHNAME(o_date), SUM(total) 
    FROM theTable
    GROUP BY YEAR(o_date), MONTH(o_date)
    
    0 讨论(0)
  • 2020-12-02 13:45
    SELECT year(FROM_UNIXTIME(created)) year, month(FROM_UNIXTIME(created)) month, sum(amount) total
    FROM {my_table}
    GROUP BY year, month
    ORDER BY year, month;
    
    0 讨论(0)
  • 2020-12-02 13:47

    Try Group BY, like this:

    select count(A_id) As Tid,Day(CrDate) from Ap Group By Day(CrDate)
    
    0 讨论(0)
  • 2020-12-02 13:59
    select year(o_date), month(o_date), sum(total)
    from table
    group by year(o_date), month(o_date);
    
    0 讨论(0)
提交回复
热议问题