duan205571 2012-11-01 14:36
浏览 17
已采纳

使用大量数据创建查询的最佳方法是什么?

I have about 360 lines of data which I need to make into 360 query's for SQL, Is there any quick way of putting all the data into one query instead of having to put them all in separate, for example here is just 3 lines of data I have:

   1,81,32
   1,101,82
   1,60,65

I have to make this data into query's so these 3 would look like:

   INSERT INTO `Fixtures` (weeks, HomeID, AwayID) Values (1,81,32);
   INSERT INTO `Fixtures` (weeks, HomeID, AwayID) Values (1,101,82);
   INSERT INTO `Fixtures` (weeks, HomeID, AwayID) Values (2,60,65);

But I have 360 lines of this, so It will be hard to make these all into query's 1 by 1, Is there any quicker way of doing this, Like just one query to insert them all?

  • 写回答

3条回答 默认 最新

  • duanbei7035 2012-11-01 14:38
    关注

    You can usually use INSERT...SELECT syntax.

    This syntax varies by db, but is often something like:

    INSERT INTO `Fixtures` (weeks, HomeID, AwayID) 
    select 1,81,32
    union all select 3,31,22
    

    Another variation is:

    INSERT INTO Fixtures
        (`weeks`, `HomeID`, `AwayID`)
    VALUES
        (1, 81, 32),
        (3, 31, 22)
    ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”