I have a doubt about multiple SQL queries.(annidate) I m using standard RDBMS system.
I wish to sum with three different conditions, one column.
Ad example If I have users with bills, and I want to make the sum of the bills paid and those to be paid and the debt respectively (which is the difference between paid and unpaid bills).
my database should be
user | bills | date payments |
1 100 12/01/2020
1 100 NULL
2 200 NULL
1 200 12/02/2020
2 100 12/03/2020
My output should be
user | payed bills | unpayed bills | debit
1 100 300 200
2 200 100 100
my idea should be count a bill with values more than 0 (because the user need to pay) and count a bills that he already payed with date "null".
so i tried to do this in SQL
select count(bills)
from...
where bills >0 and select ( count(bills) from... where data = "null")
But looking this (SQL: Multiple count statements with different criteria)
I discover the "case" state. Can work in my condition?
Someone can give me an easy example of a multiple counts of the query ?