天天看點

mysql複制一列資料庫_在MySQL中從一列複制到另一列(同一資料庫的不同表)?...

要從一列複制到另一列,可以使用INSERT INTO SELECT語句。

讓我們首先建立一個表-mysql> create table DemoTable1 (PlayerScore int);

使用插入指令在表中插入一些記錄-mysql> insert into DemoTable1 values(98);

mysql> insert into DemoTable1 values(81);

mysql> insert into DemoTable1 values(76);

mysql> insert into DemoTable1 values(88);

使用select語句顯示表中的所有記錄-mysql> select *from DemoTable1;

這将産生以下輸出-+-------------+

| PlayerScore |

+-------------+

| 98          |

| 81          |

| 76          |

| 88          |

+-------------+

4 rows in set (0.00 sec)

這是建立第二個表的查詢-mysql> create table DemoTable2 (Marks int);

這是要從一列複制到另一列(同一資料庫的不同表)MySQL的查詢-mysql> insert into DemoTable2(Marks) select PlayerScore from DemoTable1;

Records: 4 Duplicates: 0 Warnings: 0

使用select語句顯示表中的所有記錄-mysql> select *from DemoTable2;

這将産生以下輸出-+-------+

| Marks |

+-------+

| 98    |

| 81    |

| 76    |

| 88    |

+-------+

4 rows in set (0.00 sec)