【发布时间】:2021-01-12 11:08:04
【问题描述】:
我有一个数据表,每个字符串包含 4 个日期: table example 我也有我所在位置的假期和周末日历表。 calendar table
我需要计算数据表中以下对的工作日数:
- task_work_end_date 和 task_got_to_work_date
- task_got_to_work_date 和 task_assigned_date
我尝试了以下选择,但它总是显示 1 个工作日,因为我将 calendar_date 放在前面:
select data_table.*, days.work_days
from data_table
left join (
select calendar_date, count(calendar_date) as work_days
from calendar_table
where type_of_day IN ('workday', 'workday shortened')
group by calendar_date ) days
ON days.calendar_date between task_assigned_date and task_got_to_work_date
请就 SQL 提出建议以正确连接这些表。
【问题讨论】: