2016-12-25 52 views
0

我有2個表如下:如何在SQLite中將「連接」查詢存儲爲新表?

table_1

-------------------------- 
    Date   Temp 
-------------------------- 
    201309010051 82 
    201309010151 81 
    201309010251 80 

table_2

--------------------- 
    Count Temp 
--------------------- 
    121  82 
    435  81 
    657  80 

我申請一個左連接兩個table_1table_2使用下面的查詢:

SELECT * FROM table_1 LEFT JOIN table_2 
ON table_1.Temp = table_2.Temp; 

基於上述查詢,我​​如何將輸出連接表存儲爲新表?

回答

1

您需要create a new table

CREATE TABLE `new_tbl` (`date` datetime , `temp1` int , `count` int , `temp2` int); 

然後你就可以使用

INSERT INTO `new_tbl` SELECT * FROM table_1 LEFT JOIN table_2 ON table_1.Temp = table_2.Temp; 
+1

沒有這麼多。當你創建一個新表時,你需要給這個列指定名字。如果你願意,你可以使用'a1,a2,a3,a4',但是你必須擁有它 – Dekel

+0

在我對'create'語法的回答中添加了一個鏈接。 – Dekel

+0

你是什麼意思的「變量類型」? – Dekel