如何使用 MySQL 计算时间范围的周末

How to calculate weekends of time range using MySQL

我需要使用 MySQL.

计算时间范围的周末

这是我目前的情况(关于计算工作日,但我想计算周末):

select
    (floor(days / 7)* 5
    + days%7
    - case
        when 6 between wd and wd + days%7 - 1 then 1
        else 0
    end
    - case
        when 7 between wd and wd + days%7 - 1 then 1
        else 0
    end) as result
from
    (
    select
        abs(datediff('2022-05-15', '2022-05-13')) + 1 as days,
        weekday('2022-05-13') + 1 as wd ) as a;

希望我解释的好...

谢谢。

select
(floor(days / 7)* 2
+ case
    when 6 between wd and wd + days%7 - 1 then 1
    else 0
end
+ case
    when 7 between wd and wd + days%7 - 1 then 1
    else 0
end) as result 

来自 ( select abs(datediff('2022-05-15', '2022-05-13')) + 1 作为天数, 工作日('2022-05-13') + 1 作为 wd ) 作为 a;

也许这会奏效。试一试。