使用NOAA气象数据,我试图为位于美国的每个NOAA气象站生成一个“分数”。 NOAA每日天气数据存储在本地SQL Server数据库中。
这些是我要计算分数的步骤:
1) For each weather station-
A) Query / compute average of max temps for July
B) Query / compute average of max temps for January
C) Query / compute average of dew points from July
2) Take results from above queries then run it through a formula, generating a score.
理想情况下,所有操作都将使用SQL完成。
我可以获取查询并分别计算每个步骤,将所有步骤放到我遇到困难的地方。这是我现在正在使用的查询:
SELECT mJan.StationID, mJul.StationID, ROUND((100 - (mJul.AvgMaxTemp) - (mJan.AvgMaxTemp) - (mJul.AvgDewPoint)),2) as MyScore
FROM
(SELECT StationID, AVG(MaxTemp) as AvgMaxTemp, AVG(MeanDewPoint) as AvgDewPoint FROM dbo.noaasmall WHERE Month=7 AND (MaxTemp<=150) GROUP BY StationID) as mJul,
(SELECT StationID, AVG(MaxTemp) as AvgMaxTemp, AVG(MeanDewPoint) as AvgDewPoint FROM dbo.noaasmall WHERE Month=1 AND (MaxTemp<=150) GROUP BY StationID) as mJan
ORDER BY mJan.StationID
我得到了各种StationID和分数的输出,但是它不起作用。
这是SQL表格式:
这是我从查询中获得的示例输出:
答案 0 :(得分:0)
尝试一下:
t2.ID
答案 1 :(得分:0)
您可以在单个聚合查询中完成所有这些操作。但是,我将使用子查询来简化计算:
SetFile("Name",currentContext, 1, "Some text here")