I have some huge files which I have to import to the DB. They have no separators so would be fixed width. The thing is that I'd like to have the avg of some of the fields as one column, and only from the ones which are not 0.
example text(no spaces in real one):
ASDD 000 000 003
BBBB 006 004 000
CCCC 001 002 000
the resultant insert I need is
ASDD | 3
BBBB | 5 [(6+4)/2]
CCCC | 1.5 [(1+2)/2]
Right now I'm using the next code, which is obviously wrong.
LOAD DATA LOCAL
INFILE '{$file}'
INTO TABLE data
(@var1)
SET
name=SUBSTR(@var1,1,4)
avg=(SUBSTR(@var1,5,3)+SUBSTR(@var1,8,3)+SUBSTR(@var1,11,3))/3
Which generates the next entries:
ASDD | 1
BBBB | 3.33
CCCC | 1
My question is, Is there any way to do it properly with LOAD DATA LOCAL (or any other SQL directly), or should I use php istead?
The problem with PHP is that the real files has like 9M rows, 900 columns and 10k char per line and I think the import would be quite slow.