0

I need your advice on the following query that I have - Let's say that I have a table with all payments that are booked on my current account. The details of the payment contain date of the operation and hour. I would like to extract the information in a such a way so to have next to each transaction the amount of of the balance(sum of transactions' amount) since the beginning of the day up to the current transaction. The balance for each day is reset to 0.

I was thinking to join this table to itself and find all unique operations from the joined table where the date matches and the hour is less then currently reviewed operation's hour then to use sum on the group.

Still I think that there is much more intelligent solution.

Thanks in advance

here is a sample of the table. Expected result is in the last column

2
  • I don't see your query. Commented Sep 23, 2015 at 19:37
  • 1
    Please include sample table structure and data. You could use SQLFiddle.com to show us the structure and data. Also include expected results in your question Commented Sep 23, 2015 at 19:38

1 Answer 1

2

My guess is that you just want a rolling sum. Making up column names and table names, you probably want something like this in your projection (your select list). You shouldn't need to do a self-join.

SUM(transaction_amount) 
  OVER (PARTITION BY account_number, trunc(transaction_date)
            ORDER BY transaction_date) rolling_sum
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.