基于现有表MySql填充新表

时间:2017-12-05 05:12:24

标签: mysql

我有一个现有的表purchase_mast

+-----------------------------------------------------------------------------------+
|   "autoid","transaction_id","user_id","package_id","purchase_date","unique_id"    |
+-----------------------------------------------------------------------------------+
| "52","bq4ren25a8w0","CBS_00002","9789386310xxx","2017-04-25 12:30:18","SUR242241" |
| "66","j4ax039ilc00","CBS_00260","9789386310xxx","2017-06-05 12:04:23","MED767885" |
+-----------------------------------------------------------------------------------+

我创建了一个新表score_mast

+---------------------------------------------------------------------------------------------------------------+
| "autoid","user_id","genre_id","package_id","timestamp","timestring","percent_marks","level_cleared","test_id" |
+---------------------------------------------------------------------------------------------------------------+

我希望从purchase_mast,user_id + package_id逐行复制到score_mast。

这是否可以在mysql中使用,而不使用PHP脚本。如果是,那么请指导我。

1 个答案:

答案 0 :(得分:3)

如果我理解正确,您希望将user_idpackage_id字段分别从purchase_mast表格复制到user_idpackage_id字段,score_mast表。如果那是你想要做的,那么你可以做到这一点

INSERT INTO score_mast(user_id, package_id) SELECT user_id, package_id FROM purchase_mast;