V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
shanechiu
V2EX  ›  问与答

如何从一个数据集随机取数据,然后插入到另外一个数据集中,两个数据集合有关系。

  •  
  •   shanechiu · 2017-11-16 16:11:00 +08:00 · 758 次点击
    这是一个创建于 2426 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我最近在搞 mysql,遇到了问题。我尽力将问题描述清楚。

    我有四个表 comment, article, user, comment_article

    user 表与 comment 表是一对多

    article 与 comment 表是多对多,所以 comment_article 即为两者关系映射。

    article,comment,user 表都是用爬虫数据填充完毕。

    现在我有这样一个需求:

    我想填充 comment_article 表数据,但是 article 数据比 comment 数据多。

    我需要保证每篇文章下不少与五条的 comment 记录。

    我使用了 insert into comment_article (articleid) select id from article;连续插入了十次

    然后 update comment_article set comment=(select id from comment order by rand() limit 1);

    然后就出了一个 lock .... transaction 的错误 time out

    我现在脑子一团浆糊,没有思路,你们能给我些许思路了?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2702 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:28 · PVG 22:28 · LAX 07:28 · JFK 10:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.