I have the following two tables:

我有以下两张表:

        Table A
+-------------------+
|___User___|__Value_|
|    3     |  a     |
|    4     |  b     |
|    5     |  c     |
|____6_____|__d_____|



        Table B
+-------------------+
|___User___|__Value_|
|    1     |        |
|    4     |        |
|    5     |        |
|____9_____|________|

My job is to take user from Table A (and their correspondings value) and then map it to Table B and insert those values in there. So from the above example Table B should look like this after running the script:

我的工作是从表A(及其对应值)获取用户,然后将其映射到表B并将这些值插入其中。因此,从上面的例子来看,运行脚本后,表B应该是这样的:

        Table B
+-------------------+
|___User___|__Value_|
|    1     |        |
|    4     |  b     |
|    5     |  c     |
|____9_____|________|

My question is how can I construct an SQL query that will do this for me in an efficient way, if Table A contains 300,000 + entries and Table B contains 70,000 entries?

我的问题是,如果表A包含30万多个条目,而表B包含7万个条目,那么我如何构建一个SQL查询,以一种有效的方式实现这一点?

NOTES: In Table A the User field is not unique and neither is the Value field. However in Table B, both the User and Value fields are unique and should not appear more than once. Neither are primary keys for either tables.

注意:在表A中,用户字段不是唯一的,值字段也不是唯一的。然而,在表B中,用户和值字段都是惟一的,不应该出现多次。两个表的主键都不是。

3 个解决方案

#1


7

Could be this

可能是这

update table_b as b 
inner join table_a as a on a.User = b.User
set b.value = a.value 

更多相关文章

  1. 在时间戳和相应的值中选择每天的最后一个条目。
  2. 保持最新的一个字段值,直到它发生变化,然后保持其最新的字段值
  3. 替换wordpress WP_POSTS表中post_date字段的年份(4位数)
  4. 如何以varchar字段为编号?
  5. 常见几种数据库中自增字段的设置方法(转)
  6. 如何使用jQuery将输入值插入更多填充的字段?
  7. HTML Select字段通过ajax调用Web服务
  8. 阻止用户在表单字段中输入
  9. CORS错误:请求标头字段预检响应中的Access-Control-Allow-Headers

随机推荐

  1. mac 安装Android studio遇到的问题及解决
  2. Android设备管理器漏洞
  3. Android(安卓)水波效果原理与实现
  4. 后台动态添加布局文件、控件与动态设置属
  5. Android调用系统摄像头拍照并剪裁压缩
  6. android 中文 api (43) —— Chronometer
  7. Android studio 无法启动安卓模拟器
  8. Android 百分比布局
  9. 在Android中调用动态库文件(*.so)
  10. Android TabWidget/TabHost的使用