troubleshooting Question

SQL Query to find last balance per account at any point in time

Avatar of Rich Olu
Rich OluFlag for United Kingdom of Great Britain and Northern Ireland asked on
* Oracle12cSQLMicrosoft SQL ServerOracle Database
5 Comments1 Solution26 ViewsLast Modified:
Hi experts,

I have a table containing transactions over time, and the transactions using different bank accounts.

How d I contruct my query to tell me the balance per account at any specifc date?

My table looks like

Date               Purchase Desc   amount   Balance   Account Used

12/08/2017      item 1                  500         1500         Halifax
14/09/2017      item 2                  25.69      34.56         PayPal
16/09/2017      item 3                  130         1630         Halifax

So If I run the query to give me my balances as at 16/09/2017 I wlll get

PayPal   14/09/2017   34.56
Halifax     16/09/2017   1630

If I get this, then I can develop it to simply give me my total balance at any specified date by summing up all last balances from every account.

I believe I need to use ROW_NUMBER () PARTITION OVER but I'm struggling with it.

This is primarily for Oracle but SQL Server (2014) also welcome.


Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 5 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 5 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004