如何根据值

时间:2018-02-14 11:07:51

标签: oracle11g oracle10g

第二列值明智地返回行

例如:

col_1     col_2
================
A          1
B          3
C          2

结果是:

col_1      col_2
================
A           1
B           3
B           3
B           3
C           2
C           2

2 个答案:

答案 0 :(得分:0)

您可以使用此查询。

WITH yourtable (col_1, col_2)
     AS (SELECT 'A', 1 FROM DUAL
         UNION ALL
         SELECT 'A', 3 FROM DUAL
         UNION ALL
         SELECT 'C', 2 FROM DUAL)
--The data above is for test purpose only
  SELECT col_1, col_2
    FROM yourtable
         CROSS JOIN (    SELECT ROWNUM n
                           FROM DUAL
                     CONNECT BY LEVEL <= (SELECT MAX (col_2) FROM yourtable))
   WHERE n <= col_2
ORDER BY col_1;

DEMO

答案 1 :(得分:0)

又一个选择:

for