Hi All,
I am using Oracle Database Version 11.2.
I have a formula (A-B)/[(A-B)/10]. The tables that are holding the rows for this calculations are given below:
ROWS_TAB
====== ===================
Row Amount
====== ===================
A 5000
B -5000
FORMULA_TAB
======== =========== ======== =============
| ROW# | Operator | ROW | CONSTANT |
======== =========== ======== =============
| 10 | E | A | |
| 20 | - | B | |
| 30 | E | A | |
| 40 | - | B | |
| 50 | / | | 10 |
| 60 | / | | |
======== =========== ======== =============
The operator E starts a new calculation. The above formula has two sub-expressions thereby the table has two rows with E. Minus denoted by -, Plus denoted by +, Multiply denoted by *, and Division denoted by /.
I want to write single SQL query to perform this calculation. Is it achievable in SQL?
The scripts used to generate the tables are as below:
create table ROWS_TAB
(row_name VARCHAR2(1),
amount NUMBER);
create table FORMULA_TAB
(row# NUMBER,
operator VARCHAR2(1),
row_name VARCHAR2(1),
constant NUMBER);
INSERT INTO ROWS_TAB VALUES('A', 5000);
INSERT INTO ROWS_TAB VALUES('B', -5000);
INSERT INTO FORMULA_TAB VALUES(10, 'E','A',null);
INSERT INTO FORMULA_TAB VALUES(20, '-','B',null);
INSERT INTO FORMULA_TAB VALUES(30, 'E','A',null);
INSERT INTO FORMULA_TAB VALUES(40, '-','B',null);
INSERT INTO FORMULA_TAB VALUES(50, '/','',10);
INSERT INTO FORMULA_TAB VALUES(60, '/','','');
Can anyone help in writing SQL query....
Thanks in advance
Best Regards
Bilal