Reputation: 67
Could you please help me to do this in a single query?
Supose we have this table TRANSACTIONS
TRASACTIONS
ID NAME TYPE CREDIT DEBIT
1 Xavier 1 99 0
2 Andy 1 101 0
3 Sebas 2 0 99
4 Tyrel 2 0 101
I would like to get all rows that meet the following condition: If TYPE = 1, CREDIT > 100. ELSE IF TYPE = 2, DEBIT > 100.
The table result should be:
TRASACTIONS
ID NAME TYPE CREDIT DEBIT
2 Andy 1 101 0
4 Tyrel 2 0 101
Upvotes: 0
Views: 31
Reputation: 1269773
You can express this using or
:
where (type = 1 and credit > 100) or
(type = 2 and debit > 100)
Upvotes: 1