求一条sql语句

-江沐风- 2017-02-11 09:31:08
数据库test1 表order 字段: order_id, order_create_time,其他字段;
数据库test2 表record 字段: order_id, order_create_time,其他字段;

两个表的字段不同,

因为,record中的order_create_time是新增字段,

所以现在想把order表中order_id对应的order_create_time给更新到record中,通过order_id对应;

请问怎么实现呢。

大概有30万条记录;


...全文
155 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2017-02-13
  • 打赏
  • 举报
回复
update record inner join `order` on record.order_id=`order`.order_id set record.order_create_time=`order`.order_create_time
-江沐风- 2017-02-13
  • 打赏
  • 举报
回复
引用 2 楼 ACMAIN_CHM 的回复:
update record inner join `order` on record.order_id=`order`.order_id set record.order_create_time=`order`.order_create_time
谢谢。这样几十万条数据,会很慢么。
二月十六 2017-02-12
  • 打赏
  • 举报
回复
语句:
--测试数据
IF not object_ID('#order') is null
drop table #order
Go
CREATE TABLE #order
(
order_id INT ,
order_create_time DATETIME
)
Insert #order
select 1,'2016-1-1 10:01:08' UNION ALL
select 2,'2016-2-2 10:01:08' UNION ALL
select 3,'2016-3-3 10:01:08' UNION ALL
select 4,'2016-4-4 10:01:08'

IF not object_ID('#record') is null
drop table #record
Go
CREATE TABLE #record
(
order_id INT ,
order_create_time DATETIME
)
Insert #record
select 1,NULL UNION ALL
select 2,NULL UNION ALL
select 3,NULL UNION ALL
select 4,NULL
--测试数据结束
--更新语句
UPDATE #record
SET order_create_time = 1
FROM #order
WHERE #order.order_id = #record.order_id
--读取测试结果
SELECT * FROM #record

--删除临时表
DROP TABLE #order,#record



结果:


mssql写的,应该差不多



56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧