-- 计算指定日期本周的第一天和最后一天
select
day
,dayofweek(day) as dw1
,date_add(day,1 - dayofweek(day)) as Su_s -- 周日_start
,date_add(day,7 - dayofweek(day)) as Sa_e -- 周六_end
,case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end as dw2
,date_add(day,1 - case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end) as Mo_s -- 周一_start
,date_add(day,7 - case when dayofweek(day) = 1 then 7 else dayofweek(day) - 1 end) as Su_e -- 周日_end
from (
select '2018-07-01' as day union all
select '2018-07-02' as day union all
select '2018-07-03' as day union all
select '2018-07-04' as day union all
select '2018-07-05' as day union all
select '2018-07-06' as day union all
select '2018-07-07' as day union all
select '2018-07-08' as day union all
select '2018-07-09' as day union all
select '2018-07-10' as day union all
select '2018-07-11' as day union all
select '2018-07-12' as day union all
select '2018-07-13' as day union all
select '2018-07-14' as day union all
select '2018-07-15' as day union all
select '2018-07-16' as day union all
select '2018-07-17' as day union all
select '2018-07-18' as day union all
select '2018-07-19' as day union all
select '2018-07-20' as day union all
select '2018-07-21' as day union all
select '2018-07-22' as day
) t1
;