Skip to content
Advertisement

Sql Query To Sum Amount Before the Date And After Between Dates

I am looking for a SQL query to sum the amount before the date and after between dates.

I have the following table in my database. Now what I want to find out is the total sum (DebitAmount) – Sum (CreditAmount) that is before 2021 and then from 2021-01-01 to 2021-03-01:

Table Script

The Query I Have tried

The Result is in two row but i want to be sum in one row and if possible to do not use Union

Advertisement

Answer

I would suggest putting the value in two separate columns. If you want the result by account:

If you want totals, then remove Account from the SELECT and remove the GROUP BY.

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