我正在尝试将下面列出的查询结果导出到 csv 并在第一行中包含列名。但是,当我运行代码并打开 csv 时,标题被列为最后一行。我不知道为什么。我错过了什么?
SELECT 'id','state','First_Name', 'Last_Name', 'Phone','County'
UNION ALL
SELECT id, state, First_Name, Last_Name, Phone, County
FROM tx.students
GROUP BY First_Name, Last_Name, Phone,
HAVING COUNT(*)>1
ORDER BY id
INTO OUTFILE '/var/lib/mysql-files/_students_dupes_test3.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
记录顺序由您的
ORDER BY
子句表达式定义。由于基本(第一个)子查询字段类型的类型,所有id
字段值都转换为字符串类型。当然,数字在前,字母在后。将其替换为