在另一个海报的帮助下,我开发了以下代码:
Select a.[PT_FIN]
,[RESULT_DT_TM1] = max(case when RN=1 then [RESULT_DT_TM] end)
,[Weight1] = max(case when RN=1 then [WEIGHT_RESULT] end)
,[Sysbp1] = max(case when RN=1 then [SYSBP_RESULT] end)
,[DiaBP1] = max(case when RN=1 then [DIABP_RESULT] end)
,[Temp1] = max(case when RN=1 then [TEMPERATURE_RESULT] end)
,[Oxy1] = max(case when RN=1 then [OXYGEN_SAT_RESULT] end)
,[Fio1] = max(case when RN=1 then [FIO2_RESULT] end)
,[Flow1] = max(case when RN=1 then [Flow_Rate_Result] end)
,[RESULT_DT_TM2] = max(case when RN=1 then [RESULT_DT_TM] end)
,[Weight2] = max(case when RN=1 then [Weight] end)
,[Sysbp2] = max(case when RN=1 then [Sysbp] end)
,[DiaBP2] = max(case when RN=1 then [DiaBP] end)
,[Temp2] = max(case when RN=1 then [TEMPERATURE_RESULT] end)
,[Oxy2] = max(case when RN=1 then [OXYGEN_SAT_RESULT] end)
,[Fio2] = max(case when RN=1 then [FIO2_RESULT] end)
,[Flow2] = max(case when RN=1 then [Flow_Rate_Result] end)
ETC
变量末尾的每个数字对应于对象可能有数据的一行(某些对象有1行数据,有些可能有10行)。有没有一种有效的方法可以重复此代码以捕获最多10行数据,因此我不必添加例如:
[RESULT_DT_TM3]= max(case when RN=3 then [RESULT_DT_TM] end)
[Weight3]= max(case when RN=3 then [WEIGHT_RESULT] end)
[RESULT_DT_TM4] = max(case when RN=4 then [RESULT_DT_TM] end)
[Weight4]= max(case when RN=4 then [Weight_Result] end)
....