-1

我有这段代码,但它有问题:

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
4

1 回答 1

0

INTO OUTFILE必须在最后。

SELECT email, realname 
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
INTO OUTFILE "c:/mydata.csv";

见手动输入。

于 2013-02-28T11:58:06.780 回答