mysql - 我如何通过查询来适应 MYSQL 中每个月的最后一个业务/工作日?
问题描述
全部,
试图调整下面的查询来获取这个月的最后一个工作日,比如 5 月、6 月或其他什么?
select distinct
month(createddate),
year(CreatedDate),
id,
value1,
vaue2,
createddate,
count( distinct id)
from
table
and value2 IN ('harry','sally')
AND createddate > LAST_DAY( '2020-05-21') ## i need last business day here for may.
AND createddate < '2020-06-01' ## i need first day of next month here
group by month(createddate),
year(CreatedDate), id,value1, value2,createddate
我有一段时间没有使用 mysql,有没有办法可以使用函数或存储过程来找出这个问题?如果是这样
***工作日是指工作日,不是周末***
解决方案
大概,你想避免周末。所以:
(createddate > last_day('2020-05-21') and dayofweek(last_day('2020-05-21') between 2 and 6 or
createddate > last_day('2020-05-21') - interval 1 day and dayofweek(last_day('2020-05-21') = 7 or
createddate > last_day('2020-05-21') - interval 2 day and dayofweek(last_day('2020-05-21') = 1
)
推荐阅读
- arrays - 我想解构我的 api 并使用 react 返回它如何在我的用例中实现这一点?
- ssl - 托管没有 ssl 证书的 Blazor Web 应用程序
- python - 理解python中的嵌套函数
- flutter - 徽章结束并隐藏文字
- c# - 在c#中检查用户ID是否存在于Discord服务器中
- reactjs - 平面列表导航反应原生
- php - 在 laravel 7x 上找不到特征“Illuminate\Foundation\Auth\AuthenticatesUsers”
- flutter - Listview 和 Checkbox 使用 StatefulWidget(setState)
- javascript - 导出函数和module.exports有什么区别?
- asp.net - 在 ASP.NET 4.6 WebForms 上实现 AntiForgery 令牌