每两小时分组查询分析

你猜 阅读:246 2021-03-31 21:43:33 评论:0
SELECT 
	sum(water_flow) as water_flow,created_time, 
	CASE  
   WHEN DATE_FORMAT(created_time ,'%H') >= 0 and DATE_FORMAT(created_time ,'%H') < 2 then '2' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 2 and DATE_FORMAT(created_time ,'%H') < 4 then '4' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 4 and DATE_FORMAT(created_time ,'%H') < 6 then '6' 
	 WHEN DATE_FORMAT(created_time ,'%H') >= 6 and DATE_FORMAT(created_time ,'%H') < 8 then '8' 
	 WHEN DATE_FORMAT(created_time ,'%H') >= 8 and DATE_FORMAT(created_time ,'%H') < 10 then '10' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 10 and DATE_FORMAT(created_time ,'%H') < 12 then '12' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 12 and DATE_FORMAT(created_time ,'%H') < 14 then '14' 
	 WHEN DATE_FORMAT(created_time ,'%H') >= 14 and DATE_FORMAT(created_time ,'%H') < 16 then '16' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 16 and DATE_FORMAT(created_time ,'%H') < 18 then '18' 
   WHEN DATE_FORMAT(created_time ,'%H') >= 18 and DATE_FORMAT(created_time ,'%H') < 20 then '20' 
	 WHEN DATE_FORMAT(created_time ,'%H') >= 20 and DATE_FORMAT(created_time ,'%H') < 22 then '22' 
	 WHEN DATE_FORMAT(created_time ,'%H') >= 22 and DATE_FORMAT(created_time ,'%H') < 24 then '24' 
 END AS `c_hour` 
 from wlsq_data.water_flow 
where to_days(created_time) = 	to_days(now()) 
GROUP BY c_hour

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号