SQL每日一题(20220721)
select t2.姓名,
left(t2.str, 7),
count(1) as r
from (select t1.*, DATE_ADD(t1.请假时间, INTERVAL cn day) as str
from (select a.*, row_number() over (partition by 姓名,请假时间) - 1 as cn,t.help_topic_id
from (select a.*, DATEDIFF(请假时间到, 请假时间) + 1 as days from T0312 a) a
left join mysql.help_topic t on t.help_topic_id >
0 and t.help_topic_id <= a.days) t1) t2
group by t2.姓名, left(t2.str, 7)