将数据从一个表复制到另一个表并更改数据类型

时间:2019-02-05 19:07:57

标签: mysql

您好,我想将数据从一个表复制到另一个表,但是我想将varchar列转换为整数列,而表列在下面,我想将pop列转换为整数。谢谢

ea_id  int,
yr    int,
age   varchar,
sex   varchar,
eattain   varchar,
income  varchar,
pop varchar, 

--I just created another table and tried loading data like this, my new  
--table has a pop data type of integer, I am still getting a syntax error


load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads   
/file.csv'

into table ca_pop.educ_att
fields terminated by ','
enclosed by '"'
ignore 1 lines

(ea_id, @yr, age, sex, eattain,income, @pop)

set year = YEAR(STR_TO_DATE(@year,'%m/%d/%Y %k:%i'))
set pop =nullif(pop,'')
);

0 个答案:

没有答案