1

My sql table is

Week    Year    Applications
1       2017    0
2       2017    10
3       2017    20
4       2017    50
5       2017    0
1       2018    10
2       2018    0
3       2018    40
4       2018    50
5       2018    10

And I want SQL query which give below output

Week    Year    Applications
1       2017    0
2       2017    10
3       2017    30
4       2017    80
5       2017    80
1       2018    10
2       2018    10
3       2018    50
4       2018    100
5       2018    110

Can anyone help me to write below query?

2 Answers 2

2

You could use SUM() OVER to get cumulative sum:

SELECT *, SUM(Applications) OVER(PARTITION BY Year ORDER BY Week)
FROM tab
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you want a cumulative sum:

select week, year,
       sum(applications) over (partition by year order by week) as cumulative_applications
from t;

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.