Mysql
 sql >> Database >  >> RDS >> Mysql

come creare una query MySql per visualizzare il saldo corrente da credito e debito in cui più clienti hanno saldi individuali

Questo dovrebbe funzionare

  select  transaction_id, customer_id, date, credit, debit,
  abs(sum(ifnull(credit,0)) over (partition by customer_id order by date,credit,transaction_id ) - sum(ifnull(debit,0)) over(partition by customer_id order by date,debit,transaction_id)) as balance
  from ledger
  order by transaction_id;