안녕하세요. sql 어떻게 해야할지 ... 부탁드려요.
아래의 데이터에 No로 정렬되어 있는데
blue : 3 / red : 2 순으로 정렬하고 싶습니다.
GP |
No |
원하는 순서order by |
blue |
k1 |
1 |
blue |
k2 |
2 |
blue |
k3 |
3 |
blue |
k4 |
6 |
blue |
k5 |
7 |
blue |
k6 |
8 |
blue |
k7 |
11 |
blue |
k8 |
12 |
blue |
k9 |
13 |
blue |
k10 |
16 |
red |
k11 |
4 |
red |
k12 |
5 |
red |
k13 |
9 |
red |
k14 |
10 |
red |
k15 |
14 |
red |
k16 |
15 |
red |
k17 |
17 |
WITH DT AS (
SELECT 'blue' AS GP, 'k1' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k2' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k3' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k4' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k5' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k6' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k7' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k8' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k9' AS NO FROM DUAL UNION ALL
SELECT 'blue' AS GP, 'k10' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k11' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k12' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k13' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k14' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k15' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k16' AS NO FROM DUAL UNION ALL
SELECT 'red' AS GP, 'k17' AS NO FROM DUAL
)
SELECT *
FROM DT
|