dongxian1699 2015-05-04 18:11
浏览 98
已采纳

Mysql将具有特定列和unix时间戳的所有行从一个表复制到另一个表

I am currently copying all rows from Table1 to Table2 each day. Table2 is a 7 day archive of what Table1 contains each day. On average there are 150,000 rows to move over each day.

Table1

id | name | category | image | description | link

Table2

id | name | link | date

To do this I use PHP to select all rows in Table1:

SELECT name, category, link FROM Table1

Then I loop through each one and insert it into Table2:

INSERT INTO Table2 SET name = ''.$row["name"].'', link = ''.$row["link"].'', date = time()

time() is stored as an int(11) in the database. Can anybody advise if this is there is a better or more efficient way of doing this?

  • 写回答

1条回答 默认 最新

  • douju7245 2015-05-04 18:15
    关注

    You can use INSERT INTO SELECT rather than looping:

    INSERT INTO Table2(name,link,date)
    SELECT name, link, UNIX_TIMESTAMP() FROM Table1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题