I have a testDB with 2 tables.
Table 1:
Create Table Table1 (
id1 varchar(32) Not Null Primary Key,
des varchar(100),
btmdepth int
);
Table 2:
Create Table Table2 (
id1 varchar(32) Foreign Key References Table1(id1),
id2 varchar(32) Not Null Primary Key,
des varchar(100),
leng int
);
I have data in each table as below.
Table 1:
id1 des btmdepth
111 Production 2000
Table 2:
id1 id2 des leng
111 200 Tubing1 500
111 201 Tubing2 300
111 202 Tubing3 400
I want to create query to get a result as shown below:
id1 id2 des leng cumLeng bottomdepth topdepth
111 200 Tubing1 500 500 1300 (1600-300) 800 (1300-500)
111 201 Tubing2 300 800 1600(2000-400) 1300(1600-300)
111 202 Tubing3 400 1200 2000(Table1 btmdepth) 1600(2000-400)
The question is in the bracket.