[英]How do I get the number of business days between two dates for a particular month
[英]how can i find the number of business days between two of my date columns in bigquery?
這可能看起來很簡單,但我無法在網上找到解決方案(不使用函數)。我正在使用 bigquery 並希望找到兩天之間的工作日數。
df['business_days'] = np.busday_count(date1,
date2)
df['number_weekenddays'] = np.busday_count(date1,
date2,
weekmask='Sat Sun')
我正在嘗試將 python 中的上述查詢復制到 bigquery 語法中。 我怎樣才能做到這一點? 我試過了:
select
order_date,
pickup_date,
case
when date_diff(pickup_date, order_date, week) > 0
then date_diff(pickup_date, order_date, day) - (date_diff(pickup_date, order_date, week) * 2)
else
date_diff(pickup_date, order_date, day)
end
from `orders.table`
但我收到以下錯誤:
參數類型的函數 DATE_DIFF 沒有匹配的簽名:DATETIME、DATETIME、DATE_TIME_PART。 支持的簽名:DATE_DIFF(DATE, DATE, DATE_TIME_PART) at [186:10] 詳細了解 BigQuery SQL 函數。
即使有問題的日期列是日期
可能最簡單的方法是枚舉兩個日期之間的天數,並過濾掉非工作日。 generate_date_array()
很適合這個:
select o.order_date, o.pickup_date,
(
select count(*)
from unnest(generate_date_array(date(o.order_date), date(o.pickup_date))) dt
where dateofweek(dt) between 2 and 6
) cnt_business_days
from `orders.table` o
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.