能将3个Select语句连在一起么?
比如有2个Select语句:
txt_SQL_1="SELECT C_History.T_ID, P_History.M_ID, count(P_History.P_ID) AS Count_Total
FROM C_History INNER JOIN P_History ON C_History.C_ID=P_History.C_ID
GROUP BY P_History.M_ID, C_History.T_ID;"
txt_SQL_2="SELECT C_History.T_ID, P_History.M_ID, P_History.P_ID, Count(P_History.P_ID) AS Count_P
FROM C_History INNER JOIN P_History ON C_History.C_ID=P_History.C_ID
GROUP BY C_History.T_ID, P_History.M_ID, P_History.P_ID;"
txt_SQL_3=SELECT txt_SQL_2.T_ID, txt_SQL_2.M_ID, txt_SQL_2.P_ID, txt_SQL_2.Count_P, txt_SQL_1.Count_Total, Round(txt_SQL_2.Count_P/txt_SQL_1.Count_Total*100,2) AS Ratio
FROM txt_SQL_2 INNER JOIN txt_SQL_1 ON (txt_SQL_2.T_ID = txt_SQL_1.T_ID) AND (txt_SQL_2.M_ID = txt_SQL_1.M_ID);"
'首先要将 txt_SQL_1 和 txt_SQL_2 中的分号去掉'
txt_SQL_3 = " SELECT T2.T_ID, T2.M_ID, T2.P_ID, T2.Count_P, T1.Count_Total," & _
" Round(T2.Count_P/T1.Count_Total*100,2) AS Ratio" & _
" FROM (" & txt_SQL_2 & ") T2 " & _
" INNER JOIN (" & txt_SQL_1 & ") T1 " & _
" ON (T2.T_ID = T1.T_ID) AND (T2.M_ID = T1.M_ID)"