Skip to content
Advertisement

SQL – get rid of the nested aggregate select

There is a table Payment, which for example tracks the amount of money user puts into account, simplified as

What is need is to receive a table with balance before payment moment, eg:

Currently the select statement looks something like

How can I rewrite this select to get rid of the nested aggregate selection? The database in question is SQL Server 2019.

Advertisement

Answer

Thanks to other participants’ leads I came up with a query that (seems) to work:

Lots of related examples can be found here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement