我有这段代码,但它有问题:
SELECT email, realname INTO OUTFILE "c:/mydata.csv"
SUBSTRING_INDEX(SUBSTRING_INDEX(realname, ' ', 1), ' ', -1) as firstname,
SUBSTRING_INDEX(SUBSTRING_INDEX(realname, ' ', 2), ' ', -1) as lastname,
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM mytable;
我只选择电子邮件和实名字段,并在遇到空格时将实名拆分为 2 个字段!
错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SUBSTRING_INDEX(SUBSTRING_INDEX(realname, ' ', 1), ' ', -1) as firstname, SUBST' at line 2