MYSQL查询近一周数据并且为空得数据自动赋值为0
部分数据库样版
思路
1.查询近7天得数据 2.由于公司需要对时间格式取月日进行处理 3.完善部分月份无数据得情况下设值为0
select gas_date as datess,number as num
from (select * from fd_rq_gas_patrol where DATE_SUB(CURDATE(),INTERVAL 7 DAY)<=date(gas_date)
ORDER BY gas_date) as sss GROUP BY datess
查询结果为:
对时间进行处理
select DATE_FORMAT(gas_date,'%m-%d') datess,number as num
from (select * from fd_rq_gas_patrol where DATE_SUB(CURDATE(),INTERVAL 7 DAY)<=date(gas
共有 0 条评论