Suppose we have a table like:
Now the query
will produce the following result:
Case statements can also be used within a query like shown in the answer of this stackoverflow question
transaction_id | acc_no | amount |
1 | 100001 | 20000 |
2 | 100002 | 30000 |
3 | 100003 | 30000 |
4 | 100004 | 10000 |
5 | 100005 | 50000 |
select acc_no, SUM(IF(amount>20000,amount,0)) as total_value from account where acc_no=100002 group by acc_no;
will produce the following result:
acc_no | amount |
100002 | 80000 |
No comments:
Post a Comment