繁体   English   中英

从DB2中where子句中传递的日期算起工作日数

[英]Count number of weekdays from the dates passed in where clause in DB2

如何计算在where子句中传递的给定日期范围的工作日数。 例如,在下面的示例中,有13条记录,但是其中只有9条属于工作日。

select * from table_name where startdate > '2019-01-01' and enddate < '2019-01-31' Date Day Asset Price 01-01-2019 Tuesday A 5 01-01-2019 Tuesday A 23 02-01-2019 Wednesday B 20 03-01-2019 Thursday C 87 04-01-2019 Friday D 34 04-01-2019 Friday D 8 05-01-2019 Saturday E 12 05-01-2019 Saturday E 56 06-01-2019 Sunday F 214 07-01-2019 Monday G 32 08-01-2019 Tuesday H 45 09-01-2019 Wednesday I 67

select count(*)
from table_name
where startdate > '2019-01-01' and enddate < '2019-01-31'
and Day not in ("Saturday", "Sunday")

如果按原样运行,这是否是正确的结果?

with table_name (date) as 
(
  values
  '01-01-2019'
, '01-01-2019'
, '02-01-2019'
, '03-01-2019'
, '04-01-2019'
, '05-01-2019'
, '06-01-2019'
, '07-01-2019'
, '08-01-2019'
, '09-01-2019'
)
select 
—- distinct date
count(distinct date)
from table_name
where dayofweek_iso(date(to_date(date, 'DD-MM-YYYY'))) < 6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM