我有這樣的表:
表_0
| 客戶ID | 交易日期 |
|---|---|
| C001 | 22 年 9 月 1 日 |
| C001 | 22 年 9 月 4 日 |
| C001 | 22 年 9 月 14 日 |
| C002 | 22 年 9 月 3 日 |
| C002 | 22 年 9 月 1 日 |
表格1
| 客戶ID | 交易日期 |
|---|---|
| C002 | 22 年 9 月 18 日 |
| C002 | 22 年 9 月 20 日 |
| C003 | 22 年 9 月 2 日 |
| C003 | 22 年 9 月 28 日 |
表_2
| 客戶ID | 交易日期 |
|---|---|
| C004 | 22 年 9 月 8 日 |
| C004 | 22 年 9 月 18 日 |
| C004 | 22 年 9 月 20 日 |
| C005 | 22 年 9 月 18 日 |
如何在postgresql中創建一個新表,其中新表由table_0、table_1和table_2組成?謝謝你的幫助
uj5u.com熱心網友回復:
創建一個新表,例如“new_table”,然后對每個表執行以下命令:INSERT INTO new_tale SELECT * FROM table_0
uj5u.com熱心網友回復:
就是這個:
select a.CustomerID ac customer_id,
a.Trans_date as Trans_date1,
b.Trans_date as Trans_date2,
c.Trans_date as Trans_date3
where a.CustomerID=b.CustomerID
and b.CustomerID=c.CustomerID;
uj5u.com熱心網友回復:
聯合示例:https
://www.postgresqltutorial.com/postgresql-tutorial/postgresql-union/
創建表為:https ://www.postgresqltutorial.com/postgresql-tutorial/postgresql-create-table-as/
遵循示例將是:
CREATE TABLE new_table AS (
SELECT
CustomerID,
Trans_date
FROM
Table_0
UNION ALL
SELECT
CustomerID,
Trans_date
FROM
Table_1
UNION ALL
SELECT
CustomerID,
Trans_date
FROM
Table_2)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/524150.html
