近七日数据,没有数据的默认展示0

select a.click_date createTime,
ifnull(b.bloodOxygenDetectionResult,0) as bloodOxygenDetectionResult,
ifnull(b.alcoholDetectionResult,0) as alcoholDetectionResult,
ifnull(b.bloodPressureDetectionResult,0) as bloodPressureDetectionResult
from (
    SELECT curdate() as click_date
    union all
    SELECT date_sub(curdate(), interval 1 day) as click_date
    union all
    SELECT date_sub(curdate(), interval 2 day) as click_date
    union all
    SELECT date_sub(curdate(), interval 3 day) as click_date
    union all
    SELECT date_sub(curdate(), interval 4 day) as click_date
    union all
    SELECT date_sub(curdate(), interval 5 day) as click_date
    union all
    SELECT date_sub(curdate(), interval 6 day) as click_date
) a left join (
    SELECT 
	      u.nick_name nickName, u.job_number jobNumber, u.cardkey,u.health,u.sex,u.user_id userId,DATE_FORMAT(u.create_time,"%Y-%m-%d") as createtimes,
        u.alcohol_detection_result alcoholDetectionResult,u.phonenumber,
        u.blood_pressure_detection_result bloodPressureDetectionResult,
        u.blood_oxygen_detection_result bloodOxygenDetectionResult,
        u.temperature,d.dept_name deptName, r.role_name roleName,
				p.download_path downloadPath
        from sys_user_index u
        left join sys_dept d on u.dept_id = d.dept_id
        left join sys_user_role ur on u.user_id = ur.user_id
        left join sys_role r on r.role_id = ur.role_id
        LEFT JOIN sys_user_photo p ON u.job_number=p.job_number
	where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(u.create_time) and u.user_id ='2611' and u.del_flag = '0'
) b on a.click_date = b.createtimes 
ORDER BY a.click_date desc;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值