database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
ㆍOracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Oracle Q&A 41360 게시물 읽기
No. 41360
정렬 문의 드립니다.
작성자
순간선택
작성일
2017-03-17 18:33:49
조회수
796

정렬 문의 드립니다

WITH T AS (

SELECT 'A' AS GBN, '20170316130200' AS STA_DT, '20170316130700' AS END_DT FROM DUAL UNION ALL

SELECT 'B' , '20170316130200' , '20170316131400' FROM DUAL UNION ALL

SELECT 'C' , '20170316130200' , '20170316134000' FROM DUAL UNION ALL

SELECT 'D' , '20170316130200' , '20170316142400' FROM DUAL UNION ALL

SELECT 'E' , '20170316130200' , '20170316153300' FROM DUAL UNION ALL

SELECT 'F' , '20170316130700' , '20170316132600' FROM DUAL UNION ALL

SELECT 'G' , '20170316131400' , '20170316153300' FROM DUAL UNION ALL

SELECT 'H' , '20170316132600' , '20170316133600' FROM DUAL UNION ALL

SELECT 'I' , '20170316133600' , '20170316142000' FROM DUAL UNION ALL

SELECT 'J' , '20170316134000' , '20170316135300' FROM DUAL UNION ALL

SELECT 'K' , '20170316135300' , '20170316140900' FROM DUAL UNION ALL

SELECT 'L' , '20170316142000' , '20170316142700' FROM DUAL UNION ALL

SELECT 'M' , '20170316142400' , '20170316143400' FROM DUAL UNION ALL

SELECT 'N' , '20170316142700' , '20170316143300' FROM DUAL UNION ALL

SELECT 'O' , '20170316143300' , '20170316143700' FROM DUAL UNION ALL

SELECT 'P' , '20170316143400' , '20170316144800' FROM DUAL UNION ALL

SELECT 'Q' , '20170316153300' , '20170316153800' FROM DUAL

)

SELECT *

FROM T;

 

 

=================================================================================================

 

 

GBN STA_DT END_DT

A, 20170316130200, 20170316130700

F, 20170316130700, 20170316132600

H, 20170316132600, 20170316133600

I, 20170316133600, 20170316142000

L, 20170316142000, 20170316142700

 

B, 20170316130200, 20170316131400

G, 20170316131400, 20170316153300

Q, 20170316153300, 20170316153800

 

C, 20170316130200, 20170316134000

J, 20170316134000, 20170316135300

K, 20170316135300, 20170316140900

 

D, 20170316130200, 20170316142400

M, 20170316142400, 20170316143400

P, 20170316143400, 20170316144800

 

E, 20170316130200, 20170316153300

 

N, 20170316142700, 20170316143300

O, 20170316143300, 20170316143700

 

이렇게 정렬 될 수 있도록 도움 부탁드립니다.

 

 

 

 

 

 

 

 

 

이 글에 대한 댓글이 총 1건 있습니다.

기준이 애매하네요.

 

SELECT GBN,STA_DT, END_DT

FROM

(

SELECT GBN, STA_DT, END_DT, RANK() OVER(ORDER BY STA_DT) RN

FROM T

)

START WITH RN = 1

CONNECT BY PRIOR END_DT = STA_DT

ORDER SIBLINGS BY GBN

 

A 20170316130200 20170316130700

F 20170316130700 20170316132600

H 20170316132600 20170316133600

I 20170316133600 20170316142000

L 20170316142000 20170316142700

N 20170316142700 20170316143300

O 20170316143300 20170316143700

 

B 20170316130200 20170316131400

G 20170316131400 20170316153300

Q 20170316153300 20170316153800

 

C 20170316130200 20170316134000

J 20170316134000 20170316135300

K 20170316135300 20170316140900

 

D 20170316130200 20170316142400

M 20170316142400 20170316143400

P 20170316143400 20170316144800

 

E 20170316130200 20170316153300

Q 20170316153300 20170316153800

 

Q는 B에서 시작하는 것에도 있고

E에서 시작하는 것에도 있는데.. 어떻게 하죠?

 

손재균(iikii)님이 2017-03-17 18:55:10에 작성한 댓글입니다.
이 댓글은 2017-03-17 18:58:13에 마지막으로 수정되었습니다.
[Top]
No.
제목
작성자
작성일
조회
41363인덱스테이블스페이스 관련 질문입니다.
김삼
2017-03-23
848
41362odt에서 exp방법?
작성자
2017-03-20
824
41361행열질문입니다. [1]
김경태
2017-03-18
956
41360정렬 문의 드립니다. [1]
순간선택
2017-03-17
796
41359이전 data [1]
마당쇠
2017-03-17
757
41358조회 조건 [3]
아폴론
2017-03-17
783
41356where 절 조건 만드는 질문 [2]
임재흥
2017-03-13
779
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2017 DSN, All rights reserved.
작업시간: 0.097초, 이곳 서비스는
	PostgreSQL v9.6.3으로 자료를 관리합니다