0
Can we expand a column storing number somehow in the output.
I am trying to expand one column with other column having same value.

我正在尝试的列是数字。如果值为 3,则选择查询的结果应为 1、2、3,而其他列具有相同的数据。那可能吗?

For ex, 

输入表是

    Can we expand a column storing number somehow in the output.
    For ex, <br>
    <h4>INPUT TABLE IS :</h4>
     
    <table style="width:50%" border=1>
      <tr>
        <td>Thank</td>
        <td>You </td> 
        <td>2 </td>
      </tr>
      <tr>
    </table>
    <br>
    <h4>Output TABLE should be like this :</h4>
     
    <table style="width:50%" border=1>
      <tr>
        <td>Thank</td>
        <td>You </td> 
        <td>1 </td>
      </tr>
    <tr><br>
        <td>Thank</td>
        <td>You </td> 
        <td>2 </td>
      </tr>
      <tr>
    </table>
    <br><br>
    value of last column is number and has expanded.<br>
    <b>Column1 and column2 should contain same value.</b><br>
    
    The problem is that i can change the input table and this is how i need the output.<br>
    I am trying using dual table join with table1 and use CONNECT BY but not getting the result . 

<br> Any help on this..

输出表是

最后一列的值为数字并已扩展。Column1 和 column2 应该包含相同的值。

The problem is that i can change the input table and this is how i need the output.
I am trying using dual join with table1 and use CONNECT BY but not getting the result . 
4

1 回答 1

0

好的,这是获取“计数”列的逻辑...

SELECT LEVEL AS Column3
FROM DUAL
CONNECT BY LEVEL <= @EnteredNumber;

这将创建一个从 1 到您输入的数字的序列号表。您所要做的就是将这个新表格与您预先制作的结果一起加入。

它的工作原理是它创建了一个自引用循环,该循环产生“继承”,其中每一后续行都被视为前一行的子行。这很奇怪,是的......但它应该工作

编辑以调整我的答案以使用您在评论中要求的细节:

SELECT t.Column1, t.Column2, LEVEL As Column3 
FROM (
    SELECT Column1, Column2, Column3Value 
    FROM Table_1  
    WHERE t.column1='value' 
    AND t.column2 = 'value2'
) t 
CONNECT BY LEVEL <= t.Column3Value

确保您在子查询中执行 WHERE 工作,否则它将在过滤之前对整个表运行连接,这对您的性能将是可怕的。

于 2014-10-01T21:32:18.177 回答