对MySQL负载数据执行计算

时间:2011-08-25 14:58:43

标签: mysql load-data-infile

我有以下两个sql语句

LOAD DATA LOCAL INFILE '~/data/geo_blocks.csv' INTO TABLE geo_blocks FIELDS  ENCLOSED BY '\"'TERMINATED BY ',' LINES TERMINATED BY '\n' (ip_start, ip_end, location_id);

&安培;

update geo_blocks set index_geo = (ip_end - mod(ip_end, 65536));

是否有办法将LOAD DATA语句组合在一起同时执行计算?

1 个答案:

答案 0 :(得分:4)

您应该在LOAD DATA INFILE命令 -

中尝试SET子句
LOAD DATA LOCAL INFILE '~/data/geo_blocks.csv'
INTO TABLE geo_blocks
FIELDS ENCLOSED BY '\"'TERMINATED BY ','
LINES TERMINATED BY '\n'
(@ip_start, @ip_end, location_id)
SET index_geo = @ip_end - MOD(@ip_end, 65536);