我想找到最大列值,我说:
SELECT
Segment_ID.Segment_ID,
Intensity.Date,
Intensity.NumAll,
Intensity.AverageDailyIntensCar,
MAX(Intensity.AverageDailyIntensCar) as maxvalue,
Track.the_geom
FROM Segment_ID
LEFT JOIN Track ON Segment_ID.Segment_ID=Track.Segment_ID
LEFT JOIN Intensity ON Segment_ID.Segment_ID=Intensity.Segment_ID
where (DATEPART(yy, Intensity.Date) = 2009
AND DATEPART(mm, Intensity.Date) = 08
AND DATEPART(dd, Intensity.Date) = 14)
但得到错误:
Column `Segment_ID.Segment_ID` is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
所以我添加GROUP BY Segment_ID.Segment_ID
但下一列得到相同的错误。
如何正确使用 max() 函数?
UPD
我想我问错了。Bucouse 我希望 max() 函数返回我的行并在列中设置列 MAX(Intensity.AverageDailyIntensCar) as maxvalue
的最大值Intensity.AverageDailyIntensCar
。这是正确的?