0

只有 Teradata SQL 可供使用。

我正在尝试动态创建作业将在其上运行的日期列表。这是我正在处理的简化版本。

Calendar (covers 2012+)
--------
Calender Date
Business Day Flag - 1 = This is a Business Day, 0 = Weekend
Holiday Flag - 1 = This is a Holiday, 0 = Non-Holiday
Year
Month
Day

Schedule (several more fields available, but not relevant)
--------
Day Type - Business Day or Calendar Date
Day Number - Represents either a Business or Calendar Day
Eligible to run on holiday - Yes / No

通过 select 中的 case 语句完成的逻辑

when d.day_type = 'BD' and day_num = c.business_day_of_month  then 'Y'
when d.day_type = 'CD' and day_num = c.day_of_month then 'Y'
else 'N' as run_flag

但是,当 run_flag = 'Y' 和 Holiday_Flag = 1 时,应列出作业以在下一个业务/日历日运行(取决于 day_type)。

我想我需要使用领先/滞后,但我不知道我是否可以让它贯穿所涉及的逻辑。

有任何想法吗?

4

1 回答 1

1

试试这个:

select
    a.calendar_dt,
    min(b.dt) as next_business_dt
from my_calendar a
cross join my_calendar b
where a.calendar_dt < b.calendar_dt
and b.business_day_flag = 1
and b.holiday_flag = 0
group by
    a.calendar_dt
于 2012-05-23T00:02:47.033 回答