================================
©Copyright 蕃薯耀 2022-03-10
https://www.cnblogs.com/fanshuyao/
方式一:
#mysql只更新日期,不更新时分秒 #mysql只修改日期字段的年月日,不修改时分秒 UPDATE table_name SET create_time=DATE_FORMAT(CONCAT('2022-03-10 ',TIME(create_time)),'%Y-%m-%d %H:%i:%S');
方式二:
#mysql只更新日期,不更新时分秒 #mysql只修改日期字段的年月日,不修改时分秒 UPDATE device_detail l SET l.`create_time`= ADDTIME(DATE('2022-03-10') + INTERVAL 0 HOUR, TIME( l.`create_time`)) WHERE l.`id`=1;
#取每天最大值的数据 SELECT DATE_FORMAT(create_time, "%Y-%m-%d") create_time, MAX(temperature) temperature, MAX(humidity) humidity, MAX(smog) smog, MAX(fan) fan, MAX(acousto_optic) acousto_optic FROM device_detail WHERE DATE_FORMAT(create_time, "%Y-%m-%d")='2022-03-07' GROUP BY DATE_FORMAT(create_time, "%Y-%m-%d");
#取30天内的数据 SELECT * FROM device_detail WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(create_time);
#取30天内每天最大的数据 SELECT DATE_FORMAT(create_time, "%Y-%m-%d") create_time, MAX(temperature) temperature, MAX(humidity) humidity, MAX(smog) smog, MAX(fan) fan, MAX(acousto_optic) acousto_optic FROM ( SELECT * FROM device_detail WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= DATE(create_time) ) t GROUP BY DATE_FORMAT(create_time, "%Y-%m-%d");
(时间宝贵,分享不易,捐赠回馈,^_^)
================================
©Copyright 蕃薯耀 2022-03-10
https://www.cnblogs.com/fanshuyao/