首页 > 代码库 > 查询语句,将一天所有记录按小时划分

查询语句,将一天所有记录按小时划分

mysql:
select
date_format(H_TIME,‘%H‘) as HOUR,
ROUND(AVG(H_TEMPERATURE),1) as TEMP,
ROUND(AVG(H_HUMIDITY),1) as HUMIDITY
FROM  HOME_MONITOR  Where date_format(H_TIME,‘%Y-%m-%d‘) =  ‘2016-03-09‘  
group by date_format(H_TIME,‘%H‘)
order by date_format(H_TIME,‘%H‘) desc

oracle:
select
to_char(H_TIME,‘HH24‘) as HOUR,
AVG(H_TEMPERATURE) as TEMP,
AVG(H_HUMIDITY) as HUMIDITY
FROM  HOME_MONITOR  Where to_char(H_TIME,‘yyyy-MM-dd‘) =  ‘2016-03-09‘  
group by to_char(H_TIME,‘HH24‘)
order by to_char(H_TIME,‘HH24‘) desc 


来自为知笔记(Wiz)


查询语句,将一天所有记录按小时划分