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 に答える