sql - 如何使用 SQL 使用 DB2 中现有的 Holiday 表将字段更新到下一个工作日
问题描述
(DB2)以今天为例(2020-04-30),2020-05-01是我国的国定假日,2020-05-02、2020-05-03是周末,所以今天的下一个工作日是2020-05-04。
所有这三天(2020-05-01、2020-05-02、2020-05-03)都记录在“假期”表中。我只想将另一个表的值更新到下一个工作日。有什么办法吗?
解决方案
你可以做:
with
d as (select h, h + 1 day as next_day from holiday where h >= '2020-04-30')
select min(next_day) from d where next_day not in (select h from d);
请参阅DB Fiddle上的运行示例。
编辑更新
要UPDATE
在另一个表上执行,您可以执行以下操作:
update a
set d = (
select min(next_day) from (
select h, h + 1 day as next_day from holiday where h >= '2020-04-30'
) x where next_day not in (select h from holiday where h >= '2020-04-30')
)
请参阅DB Fiddle上的运行示例。
推荐阅读
- javascript - Javascript模态在弹出窗口中传递动态变量取决于动态ID?
- c# - DataGridView HeaderCell 为数字类型时不显示值
- laravel - 在 laravel 项目中具有不同的引导程序版本
- c# - 与 Lambda 的 LINQ。总计的
- canvas - 有没有办法在 R/exams 的exams2canvas 中使用 LaTeX 包?
- sql - SQL 度量行到日期列-
- php - 在 Laravel 中正确访问 API
- reactjs - 此警告的可能原因和解决方案
- nativescript - 将 PWA 版本的 Google Apps 嵌入到 Nativescript 应用程序中
- c++ - 需要有关代码堵塞问题“PARENTING PARTNERSHIP”的帮助