我想从MYsql导出到csv,并按两列排序,我找到了这个教程:http://homepage.mac.com/kelleherk/iblog/C711669388/E20060511141025/index.html 但它不适合我。如果我使用不带括号的语句,它会执行排序,但使用我的标题作为数据行。但是,如果我使用括号,它根本不做任何驯服。可能是什么问题? 我的疑问是:
SELECT 'type' ,'brand' ,'timecenter_hu' ,'karorauzlet_hu' ,'karorauzlet_hu_diff',
'karorauzlet_hu_link',
UNION (SELECT type, brand, timecenter_hu, karorauzlet_hu,
karorauzlet_hu_diff, karorauzlet_hu_link
INTO OUTFILE 'c://result.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' LINES
TERMINATED BY '\n' FROM
result ORDER BY brand);
答案 0 :(得分:-1)
我认为您需要额外的查询才能导出到CSV:
SELECT *
FROM
(SELECT 'type' ,'brand' ,'timecenter_hu' ,'karorauzlet_hu' ,'karorauzlet_hu_diff' ,'karorauzlet_hu_link'
UNION
(SELECT type, brand, timecenter_hu, karorauzlet_hu, karorauzlet_hu_diff, karorauzlet_hu_link
FROM result
ORDER BY brand)) AS tmp
INTO OUTFILE 'c://result.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';