I have a table containing the stages and sub-stages of some projects, as well as a table with specific tasks and estimated costs.
I need to somehow combine each level (steps / sub-steps) to find out how much it costs, but do it with minimal cost for performance.
To illustrate this, I will use the following data structure:
CREATE TABLE stage
(
id int not null,
fk_parent int
)
CREATE TABLE task
(
id int not null,
fk_stage int not null,
cost decimal(18,2) not null default 0
)
with the following data:
==stage==
id fk_parent
1 null
2 1
3 1
==task==
id fk_stage cost
1 2 100
1 2 200
1 3 600
I want to get a table containing the total costs for each branch. Something like that:
Stage ID Total Cost
1 900
2 300
3 600
, . , . , . , stage , D , D - (), . , .
SO,
, .
2 stage .
...
calculated_cost decimal(18,2),
date_calculated_cost datetime
...
, , datetime, , ( ). , stage date_calculated_cost, , , calculated_cost.
( stage, )
( )
, , ( , )
.
, , .