Perform airthmatic operation in select sql query when airthmatic operator stored in database
id | a | b | operation | c |
---|---|---|---|---|
1 | 2 | 3 | + | 5 |
2 | 2 | 3 | + | 6 |
3 | 3 | 2 | / | 1 |
4 | 4 | 7 | * | 28 |
5 | 54 | 2 | - | 27 |
6 | 3 | 0 | / | 0 |
select case
when operation='+' then a+b
when operation='-' then a-b
when operation='*' then a*b
when operation='/' then a/b
END
from table ;
Using in where condition while checking the value with c if airthmatic operation is equal to the the value in c coloum
select * from expressions where c= case when operation='+' then a+b
when operation='-' then a-b
when operation='*' then a*b
when operation='/' then a/b
END
Comments
Post a Comment