**COLOR** **TIMES**
ORANGE 1
RED 2
BLACK 3
YELLOW 4
但是我需要以下面的格式显示数据: -
**COLOR** **TIMES**
ORANGE 1
RED 1
RED 1
BLACK 1
BLACK 1
BLACK 1
YELLOW 1
YELLOW 1
YELLOW 1
YELLOW 1
请在oracle SQL中建议我查询
答案 0 :(得分:1)
可能的解决方案:
SQL> with t as (
2 select 'ORANGE' as color, 1 as times from dual
3 union all select 'RED' as color, 2 as times from dual
4 union all select 'BLACK' as color, 3 as times from dual
5 union all select 'YELLOW' as color, 4 as times from dual),
6 num as (
7 select rownum as n
8 from dual
9 connect by level <= 4)
10 select t.color,
11 1 as times
12 from t
13 join num on num.n <= t.times
14 order by t.times;
COLOR TIMES
------ ----------
ORANGE 1
RED 1
RED 1
BLACK 1
BLACK 1
BLACK 1
YELLOW 1
YELLOW 1
YELLOW 1
YELLOW 1
10 rows selected.
答案 1 :(得分:1)
也许不是很好但是有效:
WITH t AS
(SELECT 'Orange' AS color, 1 AS times FROM dual UNION ALL
SELECT 'Red' AS color, 2 AS times FROM dual UNION ALL
SELECT 'Black' AS color, 3 AS times FROM dual UNION ALL
SELECT 'Yellow' AS color, 4 AS times FROM dual),
t2 AS
(SELECT DISTINCT color, 1 AS item, times, LEVEL AS C
FROM t
CONNECT BY LEVEL <= times)
SELECT color, item
FROM t2;