Home > Database > Mysql Tutorial > mysql处理大数据合并的另一种方法_MySQL

mysql处理大数据合并的另一种方法_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:30:15
Original
973 people have browsed it

bitsCN.com

在做项目的时候我碰到了一个这样的场景,有两张表,数据都在300W左右,现在要求在生产环境中合并这两张表为一张表,本来想用sql语句insert into select来实现,后来发现这样操作速度很慢,因为里面有计算逻辑。大概的表结构如下:

table1

id tel credits1

 

table2

id tel credits2 points

 

合并后的表为

table

id tel credits points

 

其中credits = credits1 + credits2

 

我采用的实现方法是这样的:

 

第一步、先建一个视图。

名为table

sql语句大致如下:

select table2.id,table2.tel,table1.credits1 + table2.credits2 as credits, table2.points from table2 left join table1 on table1.tel = table2.tel

 

上线运行一天左右,基本没问题之后。找个运行空闲期,关闭项目。

 

第二步、导出视图中的数据。

第三步、重命名视图名称为table_copy。

第四步、新建表table,字段为id tel credits points

第五步、把视图中的数据导入到table中。

 

bitsCN.com
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template