这个ACCESs中的查询怎么优化下呢,5个表,Join怎么弄
这个ACCESs中的查询如何优化下呢,5个表,Join如何弄,
SELECT Forecast.YMD, Forecast.StationName, Forecast.FPID, Forecast.FW, RealWeather.RR AS 表达式1, IIf((Terms.WclassA>0),IIf(IsNull(RealWeather.RR),0,1),IIf(IsNull(Forecast.FW),Null,0)) AS 一般性降水, IIf((Terms.WclassB=1),IIf(IsNull(Forecast.FW),0,1),IIf(IsNull(RealWeather.RR),1,0)) AS 晴雨, Forecast.FTX AS FTX, RealWeather.TX AS TX, IIf(Abs(Forecast.FTX-RealWeather.TX)>20,0,1) AS 最高误差小于2度, IIf(Abs(Forecast.FTX-RealWeather.TX)>10,0,1) AS 最高误差小于1度, Forecast.FTN AS FTN, RealWeather.TN AS TN, IIf(Abs(Forecast.FTN-RealWeather.TN)>20,0,1) AS 最低误差小于2度, IIf(Abs(Forecast.FTN-RealWeather.TN)>10,0,1) AS 最低误差小于1度
FROM Forecast, StationMapStation, terms, RealWeather, ForecastPeriods
WHERE (((Forecast.StationName)=[StationMapStation].[StationName] And (Forecast.StationName) ALike [输入台站名]) AND ((Forecast.FPID)=[ForecastPeriods].[FPID]) AND ((Forecast.FW)=[Terms].[W]) AND ((StationMapStation.MapStationNumber)=[RealWeather].[StationNum]) AND ((Format(DateAdd("h",[ForecastPeriods].[T],[Forecast].[YMD]),"Short Date"))=Format([RealWeather].[YMD],"Short Date")) AND ((DatePart("yyyy",[Forecast].[YMD]))=[输入年份]) AND ((DatePart("m",[Forecast].[YMD]))=[输入月份]));
------解决思路----------------------
((Format(DateAdd("h",[ForecastPeriods].[T],[Forecast].[YMD]),"Short Date"))=Format([RealWeather].[YMD],"Short Date"))
AND
((DatePart("yyyy",[Forecast].[YMD]))=[输入年份]) AND ((DatePart("m",[Forecast].[YMD]))=[输入月份]));
这两句,加在列上的函数,转移到后面的变量上。
SELECT Forecast.YMD, Forecast.StationName, Forecast.FPID, Forecast.FW, RealWeather.RR AS 表达式1, IIf((Terms.WclassA>0),IIf(IsNull(RealWeather.RR),0,1),IIf(IsNull(Forecast.FW),Null,0)) AS 一般性降水, IIf((Terms.WclassB=1),IIf(IsNull(Forecast.FW),0,1),IIf(IsNull(RealWeather.RR),1,0)) AS 晴雨, Forecast.FTX AS FTX, RealWeather.TX AS TX, IIf(Abs(Forecast.FTX-RealWeather.TX)>20,0,1) AS 最高误差小于2度, IIf(Abs(Forecast.FTX-RealWeather.TX)>10,0,1) AS 最高误差小于1度, Forecast.FTN AS FTN, RealWeather.TN AS TN, IIf(Abs(Forecast.FTN-RealWeather.TN)>20,0,1) AS 最低误差小于2度, IIf(Abs(Forecast.FTN-RealWeather.TN)>10,0,1) AS 最低误差小于1度
FROM Forecast, StationMapStation, terms, RealWeather, ForecastPeriods
WHERE (((Forecast.StationName)=[StationMapStation].[StationName] And (Forecast.StationName) ALike [输入台站名]) AND ((Forecast.FPID)=[ForecastPeriods].[FPID]) AND ((Forecast.FW)=[Terms].[W]) AND ((StationMapStation.MapStationNumber)=[RealWeather].[StationNum]) AND ((Format(DateAdd("h",[ForecastPeriods].[T],[Forecast].[YMD]),"Short Date"))=Format([RealWeather].[YMD],"Short Date")) AND ((DatePart("yyyy",[Forecast].[YMD]))=[输入年份]) AND ((DatePart("m",[Forecast].[YMD]))=[输入月份]));
------解决思路----------------------
((Format(DateAdd("h",[ForecastPeriods].[T],[Forecast].[YMD]),"Short Date"))=Format([RealWeather].[YMD],"Short Date"))
AND
((DatePart("yyyy",[Forecast].[YMD]))=[输入年份]) AND ((DatePart("m",[Forecast].[YMD]))=[输入月份]));
这两句,加在列上的函数,转移到后面的变量上。