简体   繁体   English

将列移到mysql中的新表中

[英]Move column into new table in mysql

I'm changing my database structure and I want to do the following thing: I have one table for registered users that holds almost all the information about my site users. 我正在更改数据库结构,并且要执行以下操作:我有一个供注册用户使用的表,其中包含有关我的站点用户的几乎所有信息。 There is also one other table that holds information about the amount of points each user have. 还有另一个表,其中包含有关每个用户所拥有的积分数量的信息。 It has only two columns: user id and points. 它只有两列:用户ID和积分。 I want to move the points column in main users table so that the points aren't lost. 我想移动主要用户表中的points列,以便不会丢失积分。 I know theoretically that I have to join these two colums with user id somehow but I can't guess what would the code look like... 从理论上我知道我必须以某种方式将这两个列与用户ID结合在一起,但是我无法猜出代码是什么样的...

Hope I'm clear. 希望我很清楚。

Can anyone please help? 有人可以帮忙吗?

First, you will have to add the two column names to the structure of the first table... then do a correlated updates something like 首先,您必须将两个列名称添加到第一个表的结构中...然后进行相关更新,例如

UPDATE YourTable, YourOtherTable
   SET 
      YourTable.Points = YourOtherTable.Points,
      YourTable.PointsCol2 = YourOtherTable.PointsCol2
   WHERE 
      YourTable.id = YourOtherTable.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM