skip to Main Content

I would like to sum my day to day values into full months values

This is the current table:

Date Value
2024-01-01 12
2024-01-02 10
2024-01-03 20
2024-01-04 5
2024-02-01 15
2024-02-02 20
2024-02-03 10

I would like to create this one:

Month Value
Jan 2024 47
Feb 2024 45

Can anyone help out? 🙂

2

Answers


  1. for postgresql :

    SELECT 
        TO_CHAR("Date", 'Mon YYYY') as Month, 
        SUM(Value) as Value
    FROM 
        your table 
    GROUP BY 
        TO_CHAR("Date", 'Mon YYYY')
    ORDER BY 
        TO_DATE(Month, 'Mon YYYY');
    
    Login or Signup to reply.
  2. This is MySql standard query, you can change to the required format of the month and year

    SELECT
      DATE_FORMAT(date, '%m-%Y') AS month, sum(value)
    FROM table_name group by DATE_FORMAT(date, '%m-%Y') order by DATE_FORMAT(date, '%m-%Y);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search