`

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

sql 
阅读更多

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

 

 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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics