我试图根据两个表创建一个表。例如,我在一个名为Customer_ID的表中有一列,在另一个名为Debit_Card_Number的表中有一列。我怎样才能这样做,这样我就可以从一个表中获取Customer_ID列,从另一个表中获取Debit_card_number并创建一个表?感谢
答案 0 :(得分: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
)
答案 1 :(得分:0)
考虑使用连接。使用“左连接”可以为您提供ID,即使该ID没有匹配的卡号。您要匹配的值可能是id,假设该值在表格中,并带有卡号
create table joined_table as(
select t1.customer_id, t2.debit_card_number
from t1
inner join t2
on t1.matchValue = t2.matchValue
)