bhaghyasandar
bhaghyasandar

Reputation: 516

Subtraction in Mysql based on column value and group by

This is my table structure

enter image description here

I need to subtract Deposit And Withdrawal based on GROUP BY Bank

Expected Output

Bank  balance

1     1000.00

2     300.00

3     500.00

Upvotes: 2

Views: 57

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

You could use case when

    select  bank,  sum( case when  bankType ='Withdrawal' 
                          then -BankRs 
                          else  BankRs  end ) balance
    from your_table  
    group by bank

Upvotes: 2

Related Questions