2017-02-16 68 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 
)