SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
with my_date as (select trunc(to_date('30.12.2024', 'dd.mm.yyyy')) md from dual) SELECT d.lev FROM (SELECT * FROM (SELECT LEVEL w FROM dual CONNECT BY LEVEL <= 6) r CROSS JOIN (SELECT 1 d1, 2 d2, 3 d3, 4 d4, 5 d5, 6 d6, 7 d7 FROM dual) s) m LEFT OUTER JOIN (SELECT d.lev, d.dt, d.dt - TRUNC(d.dt, 'IW') + 1 d, trunc((d.dt - trunc(trunc(d.dt, 'MM'), 'IW')) / 7) + 1 w FROM (SELECT LEVEL lev, TRUNC(d.md, 'MM') + LEVEL - 1 dt FROM my_date d CONNECT BY LEVEl <= LAST_DAY(d.md) - TRUNC(d.md, 'MM') + 1) d) d ON d.w = m.w AND d.d = DECODE(d.d, 1, m.d1, 2, m.d2, 3, m.d3, 4, m.d4, 5, m.d5, 6, m.d6, 7, m.d7);

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear