简体   繁体   English

SQL服务器从一张表插入300万行数据到另一张表

[英]Insert 3 million rows of data from one table to other in SQL server

I have one AuditPlayers and AuditPlayersHistorytable from which i want to insert data to one new table, for example table name will be Players.我有一个AuditPlayersAuditPlayersHistorytable ,我想从中将数据插入到一个新表中,例如表名将是 Players。

In Auditplayers table I have a lot of players and some dates.Auditplayers表中,我有很多玩家和一些日期。 I want to insert from AuditPlayers & AuditPlayersHistory all players with their max(Date) into my new table Players.我想从AuditPlayersAuditPlayersHistory中插入所有具有max(Date)的玩家到我的新表 Players 中。

How can i do this?我怎样才能做到这一点? Is better with batch or without?有批次还是没有批次更好? How to do with batch?批处理怎么办?

Example of my AuditPlayers table:我的AuditPlayers 表示例:

PlayerId Date
1        2019-01-01
1        2019-02-01
100      2019-08-01

Data in new Players table should be新玩家表中的数据应该是

PlayerId Date
1        2019-02-01
100      2019-08-01

The Simple MAX and GROUP BY solve your problem Simple MAXGROUP BY解决您的问题

SELECT PlayerID, MAX(Date)Date
FROM YourTable
GROUP BY PlayerID

I think you want something like this:我想你想要这样的东西:

select playerId, max(date) as date
into players
from ((select playerId, date as date
       from AuditPlayers
      ) union all
      (select playerId, date as date
       from AuditPlayersHistorytable
      )
     ) p
group by playerId;

You can use insert if Players already exists.如果Players已经存在,您可以使用insert

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM