我非常接近这个查询(SQL Server 2008 R2):
Select selectedicao, selectedyear, selectedmonth
From weatherdaily
Where Selectedyear = 1990 and selectedmonth = 1
Group By selectedicao, selectedyear, selectedmonth
输出:
selectedicao selectedyear selectedmonth
-------------------------------------------------
KPKB 1990 1
KORD 1990 1
KFWA 1990 1
KCDW 1990 1
KFDY 1990 1
KLCK 1990 1
我只需要在另一个名为kfactor
的列中添加Max值。
此列为每个组都有数百个值,我无法在上述查询中为每个组列出单个值。
答案 0 :(得分:2)
我认为您只需要添加max()
功能。
Select selectedicao, selectedyear, selectedmonth, max(kfactor) as max_kfactor
From weatherdaily
Where Selectedyear = 1990 and selectedmonth = 1
Group By selectedicao, selectedyear, selectedmonth