1

I have a table that has a column date and value, what I need is to sum a value showing just one date column. Ex: I have this:

date       value
2018-01-01 150
2018-01-23 140

what I need:

date    sum(value)
2018-01 290
1
  • 1
    What if you have a value for 2018-03-14? Commented Oct 3, 2018 at 20:28

1 Answer 1

2

Simple solution to get sums per month:

SELECT to_char(date, 'YYYY-MM') AS mon, sum(value) AS sum_value
FROM   tbl
GROUP  BY 1;

For large tables it's cheaper to group on date_trunc('month', date) instead.

Related:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.