250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- spring
- JavaScript
- PostgreSQL
- Exception
- 설정
- git
- JDBC
- myBatis
- oracle
- Python
- STS
- Open Source
- MySQL
- Thymeleaf
- Core Java
- jpa
- AJAX
- maven
- 문서
- Tomcat
- SpringBoot
- Docker
- IntelliJ
- Source
- error
- 오픈소스
- Spring Boot
- ubuntu
- Eclipse
- MSSQL
Archives
- Today
- Total
헤르메스 LIFE
[Oracle] 달력 쿼리 셈플 본문
728x90
달력 쿼리 셈플
WITH CALENDAR AS ( SELECT CEIL((T1.RNUM + 7 - TO_NUMBER(TO_CHAR(TO_DATE('201606' || LPAD(TO_CHAR(T1.RNUM), 2, '0'), 'YYYYMMDD'), 'D'))) / 7) WOM, TO_CHAR(TO_DATE('201606' || LPAD(TO_CHAR(T1.RNUM), 2, '0'), 'YYYYMMDD'), 'D') DOW, '201606' || LPAD(TO_CHAR(T1.RNUM), 2, '0') CAL_YMD, T1.RNUM DOM FROM (SELECT ROWNUM RNUM FROM ALL_OBJECTS WHERE ROWNUM <= 31) T1 WHERE TO_CHAR(LAST_DAY(TO_DATE('201606' || '01', 'YYYYMMDD')), 'DD') >= LTRIM(TO_CHAR(T1.RNUM, '00')) ) SELECT TO_CHAR(MAX(DECODE(T1.DOW, '1', T1.DOM))) SUN_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '2', T1.DOM))) MON_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '3', T1.DOM))) TUE_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '4', T1.DOM))) WED_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '5', T1.DOM))) THU_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '6', T1.DOM))) FRI_EMP_NM, TO_CHAR(MAX(DECODE(T1.DOW, '7', T1.DOM))) SAT_EMP_NM, T1.WOM || '주' AS WEEK, 1 SORT_ORDER, MAX(DECODE(T1.DOW, '1', LPAD(TO_CHAR(T1.DOM), 2, '0'))) SUN, MAX(DECODE(T1.DOW, '2', LPAD(TO_CHAR(T1.DOM), 2, '0'))) MON, MAX(DECODE(T1.DOW, '3', LPAD(TO_CHAR(T1.DOM), 2, '0'))) TUE, MAX(DECODE(T1.DOW, '4', LPAD(TO_CHAR(T1.DOM), 2, '0'))) WED, MAX(DECODE(T1.DOW, '5', LPAD(TO_CHAR(T1.DOM), 2, '0'))) THU, MAX(DECODE(T1.DOW, '6', LPAD(TO_CHAR(T1.DOM), 2, '0'))) FRI, MAX(DECODE(T1.DOW, '7', LPAD(TO_CHAR(T1.DOM), 2, '0'))) SAT FROM CALENDAR T1 GROUP BY T1.WOM UNION ALL SELECT MAX(DECODE(T1.DOW, '1', '')) AS SUN_EMP_NM, MAX(DECODE(T1.DOW, '2', '')) AS MON_EMP_NM, MAX(DECODE(T1.DOW, '3', '')) AS TUE_EMP_NM, MAX(DECODE(T1.DOW, '4', '')) AS WED_EMP_NM, MAX(DECODE(T1.DOW, '5', '')) AS THU_EMP_NM, MAX(DECODE(T1.DOW, '6', '')) AS FRI_EMP_NM, MAX(DECODE(T1.DOW, '7', '')) AS SAT_EMP_NM, T1.WOM || '주' AS WEEK, 2 SORT_ORDER, MAX(DECODE(T1.DOW, '1', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) SUN, MAX(DECODE(T1.DOW, '2', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) MON, MAX(DECODE(T1.DOW, '3', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) TUE, MAX(DECODE(T1.DOW, '4', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) WED, MAX(DECODE(T1.DOW, '5', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) THU, MAX(DECODE(T1.DOW, '6', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) FRI, MAX(DECODE(T1.DOW, '7', '201606' || LPAD(TO_CHAR(T1.DOM), 2, '0'))) SAT FROM CALENDAR T1 GROUP BY T1.WOM ORDER BY WEEK, SORT_ORDER
728x90
'Database' 카테고리의 다른 글
[Oracle] IMP/EXP 시 에러 발생 (EXP-00008) (0) | 2020.11.18 |
---|---|
[Import] Oracle 11g -> Oracle XE 11.2 오류해결 (0) | 2020.11.18 |
[Oracle] 연속된 날짜 생성 쿼리 (0) | 2016.04.25 |
[Oracle] 중복기간 체크 (0) | 2016.04.25 |
[Oracle] 전일, 전주, 전월, 전분기, 전반기, 전년도 구하기 (0) | 2016.04.19 |