我有一张大桌子,大约有 200 个字段。从其中创建维度表时,大约有 100 个字段将映射到一个字段。问题是我必须像 100 个插入语句一样将这 100 个字段的值一一添加。有没有像循环或其他东西可以让我更有效地实现这一目标?
下面是代码示例:
insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_18,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
from svch_dischs3_s D3, svch_diags_s D
insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_19,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
from svch_dischs3_s D3, svch_diags_s D
insert into DimTableA(visit_no, patient, facility, icd9, icd9_flag, ip_op)
select D.registration, D3.med_number, D3.Hosp_Id, D.final_diagnosis_20,'d',IF(D3.Admit_Type in(1,2,3),'Inpatient','Outpatient'),
from svch_dischs3_s D3, svch_diags_s D;
......... 等等
唯一更改的字段名称是“icd9”输入(即 D.final_diagnosis_18、final_diagnosis_19、final_diagnosis_20 ....)
小伙子们,任何帮助将不胜感激。:)