SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with recursive date_cte as ( select date_format('2005-07-01', '%Y-%m-%d') as date_jul, sum(0) as week union all select adddate(date_jul, interval 1 day), (case when dayofweek(date_jul) = 1 or dayofweek(date_jul) = 7 then week + 1 else week + 0 end) as week from date_cte where date_jul != '2005-07-31' ) -- select sum( -- case when dayofweek(date_jul) = 1 or dayofweek(date_jul) = 7 then 1 else 0 end -- ) as weekend_days -- from date_cte select max(week) as weekend_days from date_cte

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear