甲骨文数据库:SQL_FIDDLE
这是关于计数和每周周期的开始:
Table_1 列出了计划及其开始日期。
表_2 列出了表_1 中的期间和相应的计划。
选择
select
t2.PERIOD
,'WEEK_NUMBER ' || to_char(t1.START_DATE +((t2.PERIOD-1) * 7), 'iw') Week
,to_char(t1.START_DATE + ((t2.PERIOD-1) * 7), 'YYYY-MM-DD') Period_Start
from TABLE_1 t1
join
TABLE_2 t2
on t1.PLAN = t2.PLAN
打印以下内容:
+--------+----------------+--------------+
| PERIOD | WEEK | PERIOD_START |
+--------+----------------+--------------+
| 1 | WEEK_NUMBER 18 | 2020-05-01 |
| 2 | WEEK_NUMBER 19 | 2020-05-08 |
| 3 | WEEK_NUMBER 20 | 2020-05-15 |
| 4 | WEEK_NUMBER 21 | 2020-05-22 |
| 5 | WEEK_NUMBER 22 | 2020-05-29 |
| 6 | WEEK_NUMBER 23 | 2020-06-05 |
| 7 | WEEK_NUMBER 24 | 2020-06-12 |
| 8 | WEEK_NUMBER 25 | 2020-06-19 |
+--------+----------------+--------------+
问题:每个时期应该有 7 天,除了有一个月休息的时期。如果一个周期包括一个月的休息,它应该到该月的最后一天,其余的应该作为下个月的新周期继续。应调整周数和周期数。
例子:
+--------+----------------+--------------+
| PERIOD | WEEK | PERIOD_START |
+--------+----------------+--------------+
| 1 | WEEK_NUMBER 18 | 2020-05-01 |
| 2 | WEEK_NUMBER 19 | 2020-05-08 |
| 3 | WEEK_NUMBER 20 | 2020-05-15 |
| 4 | WEEK_NUMBER 21 | 2020-05-22 |
| 5 | WEEK_NUMBER 22 | 2020-05-29 |< --- period part before new month
| 6 | WEEK_NUMBER 23 | 2020-06-01 |< --- period part after new month
| 7 | WEEK_NUMBER 23 | 2020-06-05 |
| 8 | WEEK_NUMBER 24 | 2020-06-12 |
| 9 | WEEK_NUMBER 25 | 2020-06-19 |
+--------+----------------+--------------+
这里推荐哪种程序?
我添加了另一个带有附加句点的SQL_FIDDLE:
+--------+----------------+--------------+
| PERIOD | WEEK | PERIOD_START |
+--------+----------------+--------------+
| 1 | WEEK_NUMBER 23 | 2020-06-01 |
| 2 | WEEK_NUMBER 24 | 2020-06-08 |
| 3 | WEEK_NUMBER 25 | 2020-06-15 |
| 4 | WEEK_NUMBER 26 | 2020-06-22 |
| 5 | WEEK_NUMBER 22 | 2020-05-29 |< --- period part before new month
| 6 | WEEK_NUMBER 23 | 2020-06-01 |< --- period part after new month (Week_Number has changed)
| 6 | WEEK_NUMBER 28 | 2020-07-06 |
| 7 | WEEK_NUMBER 29 | 2020-07-13 |
| 8 | WEEK_NUMBER 30 | 2020-07-20 |
| 9 | WEEK_NUMBER 31 | 2020-07-27 |< --- period part before new month
| 10 | WEEK_NUMBER 31 | 2020-08-01 |< --- period part afternew month (Week_Number has not changed)
| 11 | WEEK_NUMBER 32 | 2020-08-03 |
| 12 | WEEK_NUMBER 33 | 2020-08-10 |
| 13 | WEEK_NUMBER 34 | 2020-08-17 |
| 14 | WEEK_NUMBER 35 | 2020-08-24 |
| 15 | WEEK_NUMBER 36 | 2020-08-31 |< --- period part before new month
| 16 | WEEK_NUMBER 36 | 2020-09-01 |< --- period part before new month (Week_Number has not changed)
| 15 | WEEK_NUMBER 37 | 2020-09-07 |
| 16 | WEEK_NUMBER 38 | 2020-09-14 |
+--------+----------------+--------------+