MM MON
TUE
WED
THR
FRI
SAT
SUN
01
1 mat1:1-2:12
2 mat2:13-3:6
3 mat3:7-4:11
4 mat4:12-25
5 mat5:1-26
6 mat5:27-48
01 7 mat6:1-24
8 mat6:25-7:14 9 mat7:15-29
10 mat8:1-17
11 mat8:18-34
12 mat9:1-17
13 mat9:18-38
01 14 mat10:1-23
15 mat10:24-11:6 16 mat11:7-30
17 mat12:1-21
18 mat12:22-45 19 mat12:46-13:2320 mat13:24-46
01 21 mat13:47-14:12 22 mat14:13-36 23 mat15:1-28
24 mat15:29-16:1225 mat16:13-17:9 26 mat17:10-27 27 mat18:1-20
01 28 mat18:21-19:12 29 mat19:13-30 30 mat20:1-28
31 mat20:29-21:22
02
1 mat21:23-46
2 mat22:1-33
3 mat22:34-23:12
02 4 mat23:13-39
5 mat24:1-28
6 mat24:29-51
7 mat25:1-30
8 mat25:31-26:13 9 mat26:14-46
10 mat26:47-68
02 11 mat26:69-27:14 12 mat27:15-31 13 mat27:32-66 14 mat28:1-20
15 mak1:1-28
16 mak1:29-2:12 17 mak2:13-3:63
02 18 mak3:7-30
19 mak3:31-4:25 20 mak4:26-5:20 21 mak5:21-43
22 mak6:1-29
23 mak6:30-56
24 mak7:1-23
02 25 mak7:24-8:10 26 mak8:11-38
27 mak9:1-29
28 mak9:30-10:12
with as table named cal in two column (mon & day) plus todo column (pr),
how to build a calendar in pure Oracle SQL?
select mm, mon, tue, wed, thr, fri, sat, sun from (
select mm,
lag(dd, 6) over ( partition by mm order by dd ) mon_flag,
lag(todo, 6) over ( partition by mm order by dd ) mon,
lag(todo, 5) over ( partition by mm order by dd ) tue,
lag(todo, 4) over ( partition by mm order by dd ) wed,
lag(todo, 3) over ( partition by mm order by dd ) thr,
lag(todo, 2) over ( partition by mm order by dd ) fri,
lag(todo, 1) over ( partition by mm order by dd ) sat,
ot sun,
dd sun_flag
from (
with dml as (
select trunc(sysdate,'yy')+level-1 dd from dual
connect by level<=add_months(sysdate,12)-sysdate
)
select dd, ot, to_char(dd, 'MM') mm from dml
natural join (
select to_date(mon||'-'||day, 'mm-dd') dd,
day||' '||pr todo from cal
)
union all
select null, null, to_char(dd, 'MM') mm from dml
)
)
where to_char(sun_flag,'d')=1 or to_char(mon_flag,'d')=2
/
没有评论:
发表评论