0

テーブルから 1 つの値を取得し、この値を別のテーブルに挿入する方法を教えてください。

Table1     Table2
Col1       Col1  Col2 
10         16    Null 
4          17    Null
8
9

以下に示すように、Table2に値を挿入したいと思います。

    Table2
    column 1   column 2
    10          16
    10          17
    4           16
    4           17
    8           16
    8           17
    9           16
    9           17
4

2 に答える 2

1
INSERT INTO table2 
SELECT t1.col1, 
       t2.col2 
FROM   (SELECT Row_number() 
                 OVER( 
                   ORDER BY (SELECT 0)) rno, 
               * 
        FROM   table1) t1 
       CROSS JOIN table2 t2 
ORDER  BY t1.rno  
Go
delete from table2 where col2 is null
于 2013-09-26T08:50:27.190 に答える
0

次を使用できますcross join

フィドルのデモ

insert into table2
select t1.col1 , t2.col1 col2
from table1 t1 cross join table2 t2;


--if you don't need null values
delete table2 where col2 is null;

--results
select * from table2;
于 2013-09-26T09:05:19.967 に答える