我尝试了这个,但它没有工作,请给出解决方案......
select DATE_FORMAT(patient_blood_sugar_record_date,'%a')as Pdate,patient_blood_sugar_Pre_fasting
from
(
select patient_blood_sugar_record_date,patient_blood_sugar_Pre_fasting
from patient_blood_sugar_record
where patient_blood_sugar_record_date BETWEEN date_add(curdate(), interval -6 day) AND curdate()
group by patient_blood_sugar_record_date
union all
select curdate(), 0
union all
select date_add(curdate(), interval -1 day), 0
union all
select date_add(curdate(), interval -2 day), 0
union all
select date_add(curdate(), interval -3 day), 0
union all
select date_add(curdate(), interval -4 day), 0
union all
select date_add(curdate(), interval -5 day), 0
union all
select date_add(curdate(), interval -6 day), 0
) x
group by patient_blood_sugar_record_date
order by patient_blood_sugar_record_date;
答案 0 :(得分:0)
请在下面示例: -
SELECT * FROM table WHERE date_column> =(CURDATE() - INTERVAL 10 DAY)
答案 1 :(得分:0)
试试这个。它具有LEFT JOIN,可以提供您想要的结果。
select DATE_FORMAT(f.dts,'%a') as Pdate,ifnull(patient_blood_sugar_Pre_fasting,0) patient_blood_sugar_Pre_fasting
from (select curdate() dts
union all
select date_add(curdate(), interval -1 day)
union all
select date_add(curdate(), interval -2 day)
union all
select date_add(curdate(), interval -3 day)
union all
select date_add(curdate(), interval -4 day)
union all
select date_add(curdate(), interval -5 day)
union all
select date_add(curdate(), interval -6 day)) f
left join
(select date_format(patient_blood_sugar_record_date,'%a') patient_blood_sugar_record_date,
min(patient_blood_sugar_Pre_fasting) patient_blood_sugar_Pre_fasting
from patient_blood_sugar_record
where patient_blood_sugar_record_date BETWEEN date_add(curdate(), interval -6 day) AND curdate()
group by date_format(patient_blood_sugar_record_date,'%a')
) x
on DATE_FORMAT(f.dts,'%a') = patient_blood_sugar_record_date
order by patient_blood_sugar_record_date;