V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
shanechiu
V2EX  ›  问与答

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

  •  
  •   shanechiu · Nov 16, 2017 · 1034 views
    This topic created in 3083 days ago, the information mentioned may be changed or developed.

    我最近在搞 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

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5238 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 01:16 · PVG 09:16 · LAX 18:16 · JFK 21:16
    ♥ Do have faith in what you're doing.