일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Android
- Spring
- oracle
- Eclipse
- ibsheet
- WebLogic
- PLSQL
- 선택적조인
- JDOM
- rowspan
- dock
- iBATIS
- swingx
- appspresso
- sencha touch
- tomcat
- JSON
- 전자정부프레임워크
- MFC
- jQuery
- node.js
- Google Map
- PHP
- MySQL
- jsr 296
- 가우스
- Struts
- phonegap
- Ajax
- GPS
Archives
- Today
- Total
Where The Streets Have No Name
Pivot working days of a month 본문
http://forums.oracle.com/forums/thread.jspa?threadID=609947
with month as (
select trunc(sysdate,'mon')+rownum-1 any_dt
from dual
connect by level <= to_number(to_char(last_Day(sysdate),'dd'))
),
days as (
select any_dt, to_char(any_dt,'DD') dy,
ceil(( 7+(trunc(any_dt,'d')-trunc(any_dt,'mon')) )/7) wk, to_char(any_dt,'D') wd
from month
)
select max(decode(wd,'1',dy,null)) d1,
max(decode(wd,'2',dy,null)) d2,
max(decode(wd,'3',dy,null)) d3,
max(decode(wd,'4',dy,null)) d4,
max(decode(wd,'5',dy,null)) d5,
max(decode(wd,'6',dy,null)) d6,
max(decode(wd,'7',dy,null)) d7
from days
group by wk
order by wk
/
D1 D2 D3 D4 D5 D6 D7
-- -- -- -- -- -- --
01 02 03 04 05
06 07 08 09 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
5 rows selected.
with month as (
select trunc(sysdate,'mon')+rownum-1 any_dt
from dual
connect by level <= to_number(to_char(last_Day(sysdate),'dd'))
),
days as (
select any_dt, to_char(any_dt,'DD') dy,
ceil(( 7+(trunc(any_dt,'d')-trunc(any_dt,'mon')) )/7) wk, to_char(any_dt,'D') wd
from month
)
select max(decode(wd,'1',dy,null)) d1,
max(decode(wd,'2',dy,null)) d2,
max(decode(wd,'3',dy,null)) d3,
max(decode(wd,'4',dy,null)) d4,
max(decode(wd,'5',dy,null)) d5,
max(decode(wd,'6',dy,null)) d6,
max(decode(wd,'7',dy,null)) d7
from days
group by wk
order by wk
/
D1 D2 D3 D4 D5 D6 D7
-- -- -- -- -- -- --
01 02 03 04 05
06 07 08 09 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
5 rows selected.