mysql - SQL insert into select from - insert the id instead of the data -
i need populate fact table data lds_placement
table. have selected records , here looks like:
fk1_account_id | fk3_job_role_id | salary | no_of_placements | year --------------------------------------------------------------------- 10 | 3 | 165000 | 5 | 2010 10 | 3 | 132000 | 4 | 2011 10 | 3 | 132000 | 4 | 2012 20 | 2 | 990000 | 3 | 2010 20 | 2 | 132000 | 2 | 2011 20 | 2 | 132000 | 2 | 2012
i want insert time_id
different table called time_dim
column year
, not actual year itself.
the time_dim
table looks this:
time_id | year --------------- 5 | 2015 1 | 2013 2 | 2010 3 | 2014 4 | 2012 6 | 2011
i need insert "year" column actually:
year 2 6 4 2 6 4
please give me way insert time_id
instead of year
in table. here code used select top-most table.
select fk1_account_id, fk3_job_role_id, sum(actual_salary) salary, count(1) no_of_placements, max(extract(year plt_estimated_end_date)) year lds_placement group fk1_account_id, fk3_job_role_id, extract(year plt_estimated_end_date) order fk1_account_id;
use left join
if want capture records year
doesn't exist in time_dim
. else use inner_join
.
select t.fk1_account_id,t.fk3_job_role_id,t.salary,t.no_of_placements ,d.time_id (select fk1_account_id, fk3_job_role_id, sum(actual_salary) salary, count(1) no_of_placements, max(extract(year plt_estimated_end_date)) year lds_placement group fk1_account_id, fk3_job_role_id, extract(year plt_estimated_end_date) )t left join time_dim d on t.year=d.year order t.fk1_account_id
Comments
Post a Comment