2017-02-16 71 views
0

我試圖根據兩個表創建一個表。例如,我在一個名爲Customer_ID的表中有一列,在另一個名爲Debit_Card_Number的表中有一列。我怎樣才能做到這一點,我可以從一個表中獲取Customer_ID列,從另一個表中獲取Debit_card_number並製作一個表格?謝謝在SQL中的兩個表中創建一個表

+0

還有什麼在借記卡表中? –

+0

使用從2現有的連接使用選擇到。如果沒有辦法告訴您哪個借記卡號碼屬於哪個客戶ID,那麼您可能會走運。 –

+0

** **您的問題,並根據該數據添加一些示例數據和預期輸出。 [**格式化文本**](http://stackoverflow.com/help/formatting)請,[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i-not 285557#285557) –

回答

0

假設兩個表名稱TableOne和TableTwo和CustomerID作爲公共屬性。

CREATE TABLE NEW_TABLE_NAME AS (
    SELECT 
     TableOne.Customer_ID, 
     TableTwo.Debit_Card_Number 
    FROM 
     TableOne, 
     TableTwo 
    Where 
    tableOne.CustomerID = tableTwo.CustomerID 
) 
0

使用連接進行調查。即使沒有與該身份證相匹配的卡號,也可以使用左連接爲您提供身份證。您的匹配值可能是id,假設該值在卡片號碼錶中

create table joined_table as(
    select t1.customer_id, t2.debit_card_number 
    from t1 
    inner join t2 
    on t1.matchValue = t2.matchValue 
)