postgres里建立工作日表

首先创建工作日历表

create table calendar_date (
  calendar_day   date not null primary key,
  week_number int,
  is_working_day char(1) not null
);

2020年每一天插入表中

insert into calendar_date(calendar_day,week_number,is_working_day) SELECT the_day,extract('ISODOW' FROM the_day),'Y'
FROM   generate_series(timestamp '2020-01-01'
                     , timestamp '2020-12-31'
                     , interval  '1 day') the_day

变更周六、日为非工作日

update calendar_date set is_working_day='N' where week_number>5;

查询5个工作日前的日期

select calendar_day from calendar_date where calendar_day<=current_date and is_working_day='Y' order by calendar_day desc offset 5 limit 1

查询出calendar_day后,所有小于该日期的记录都是超出5个工作日的记录。
可以按照国家发布的节假日,调整该表中的is_working_day即可准确的算出工作日

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 最近项目中用到自定义日历组件,找来找去,最后发现GitHub的material-calendarview这个项目最...
    colin2017阅读 1,724评论 0赞 0
  • 5Python集合容器 数据结构数据结构 一般将数据结构分为两大类: 线性数据结构和非线性数据结构。 线性数据结构...
    清清子衿木子水心阅读 1,791评论 0赞 1
  • 手动不易,转发请注明出处 --Trance 数据库系统命令: (1).查看存储过程状态:show pro...
    Trance_b54c阅读 1,915评论 0赞 8
  • 天己亮,懒起床,跨年夜里几疯狂。 凭栏依窗,楼顶白云铺张, 艳阳天,好一番新年气象! 冲一杯茶,袅袅盈香, 为新年...
    竹林主人阅读 434评论 0赞 0

友情链接更多精彩内容