超三天预警,这三天不包括工作日怎么弄

比如说今天是2023-02-13周一,由于2023-02-11,2023-02-12是非工作日,那预警就是从2023-02-08开始预警(预警比如说2023-02-08之前的数据标注成红色);比如说今天是2023-02-16周四,由于2023-02-16,2023-02-15,2023-02-14,2023-02-13都是工作日那就从2023-02-13开始预警;如果今天是2023-02-12正好是非工作日,那就从2023-02-07号开始预警,我数据库有工作日的维度表,请问这种情况要怎么实现

FineReport SQL 用户d9908268 发布于 2023-2-13 17:49
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
shirokoLv6资深互助
发布于2023-2-13 20:35

是不包括非工作日吧  有工作日维度表的话好处理。

例子----

with gzr as (

select '2023-02-06' d union all 

select '2023-02-07' union all 

select '2023-02-08' union all 

select '2023-02-09' union all 

select '2023-02-10' union all 

select '2023-02-13' union all 

select '2023-02-14' union all 

select '2023-02-15' union all 

select '2023-02-16' union all 

select '2023-02-17'

)

select min(d) from (

select d from gzr

where d<DATE_FORMAT(NOW(),'%Y-%m-%d')

order by d desc

limit 3 ) a

image.png

只要找工作日表中小于今天的日子,其中排第三的就是预警起始日了

  • 2关注人数
  • 339浏览人数
  • 最后回答于:2023-2-13 20:35
    请选择关闭问题的原因
    确定 取消
    返回顶部