日期:2014-05-16  浏览次数:20455 次

统计数据中最大值、最小值和它们分别出现的时间

统计数据中最大值、最小值和它们分别出现的时间

?

?select t.*,

?(select timestamp ?from ?hisdata ?where pointname=t.pointname and realvalue=t.minvalue ?limit 1) as mintime,

?(select timestamp ?from ?hisdata ?where pointname=t.pointname and realvalue=t.maxvalue limit 1) as maxtime?

? from (select pointname ,max(realvalue) as maxvalue, min(realvalue) as minvalue,

? ? ? ? ? cast(avg(realvalue) as numeric(10,4)) as avgvalue from ?hisdata ?group by pointname ?)t