Skip to content
Snippets Groups Projects
Commit f9644864 authored by mpotterf's avatar mpotterf
Browse files

including thinning variable in the SQL query

parent 634bbcf0
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,8 @@ create_table_OPERS2 <- 'CREATE TABLE OPERS2 AS SELECT t.id, t.branch, t.op_date,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and op_res.assortment =2 and op_res.sp = 2),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_pulp_spruce,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and op_res.assortment =1 and (op_res.sp = 3 or op_res.sp = 4)),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_log_birch,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and op_res.assortment =2 and (op_res.sp = 3 or op_res.sp = 4)),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_pulp_birch,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and (op_res.assortment =2 or op_res.assortment =1) and op_res.sp > 4),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_others,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and (op_res.assortment =2 or op_res.assortment =1) and op_res.sp > 4),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_others,
case when t.op_name = "thinning" OR t.op_name = "first_thinning" then t.op_date else 0 end as THIN,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and op_res.assortment =1 and op_res.sp > 4),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_log_others,
ifnull((SELECT sum(op_res.Volume) FROM op_res WHERE t.op_id = op_res.op_id and op_res.assortment =2 and op_res.sp > 4),0)/((select count(*) from (select * from op_res where t.op_id = op_res.op_id) x)/(select count(*) from (select distinct * from op_res where t.op_id = op_res.op_id ) x) ) AS Harvested_V_pulp_others,
......@@ -73,7 +74,7 @@ create_table_OPERS3 <- 'CREATE TABLE OPERS3 AS SELECT distinct id, branch, op_da
sum(income_biomass) as income_biomass, sum(Biomass) as Biomass,
sum(Harvested_V_log_pine* P_PINE_LOG + Harvested_V_log_spruce* P_SPRUCE_LOG+ Harvested_V_log_birch* P_BIRCH_LOG) as income_log_change,
sum(Harvested_V_pulp_pine* P_PINE_PULP+ Harvested_V_pulp_spruce* P_SPRUCE_PULP+ Harvested_V_pulp_birch* P_BIRCH_PULP+ Harvested_v_others* P_OTHER)as income_pulp_change,
sum(cash_flow) as cash_flow,
sum(cash_flow) as cash_flow, thin
SCAR, PLANTING,SEEDING,
sum(Harvested_V_log_pine*0.88 +Harvested_V_log_spruce*0.898 +Harvested_V_log_birch*0.885+Harvested_V_log_others*0.874) as Harvested_V_log_under_bark,
......@@ -99,7 +100,7 @@ create_table_UNIT <- 'Create Table UNIT AS SELECT u.*,
(select sum(stratum.V) From stratum where stratum.data_id = u.data_id and SP = 9) as V_o_decidious,
l.data_date, b.branch, b.branch_desc, b.branching_group, o.income/u.AREA as income, o.cash_flow/u.AREA as cash_flow, o.clearcut, o.Harvested_V_log/u.AREA as Harvested_V_log,
o.Harvested_V_pulp/u.AREA as Harvested_V_pulp, o.Harvested_V/u.AREA as Harvested_V, m.max_v, o.income_log/u.AREA as income_log, o.income_pulp/u.AREA as income_pulp,
o.income_log_change/u.AREA as income_log_change,o.income_pulp_change/u.AREA as income_pulp_change, o.income_biomass, o.Biomass/u.AREA as Biomass,
o.income_log_change/u.AREA as income_log_change,o.income_pulp_change/u.AREA as income_pulp_change, o.income_biomass, o.Biomass/u.AREA as Biomass, o.thin
o.Harvested_biomass_Ton/u.AREA as Biomass_ton,
o.Harvested_V_pulp_under_bark/u.AREA as Harvested_V_pulp_under_bark,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment