从 MySQL 导出带标题的 CSV 文件的排序问题

发布于 2024-12-03 12:00:24 字数 672 浏览 0 评论 0原文

我想从 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);

I want to export from MYsql to csv with ordered by two columns, i found this tutorial: http://homepage.mac.com/kelleherk/iblog/C711669388/E20060511141025/index.html
But its not working for me properly. If I use the statement without parenthesis, it does the ordering, but using my header as a data row. But if I use the parenthesis, it does not do any oredring at all. What can be the problem?
My query is:

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2024-12-10 12:00:24

我认为您需要额外的查询才能导出到 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';

I think you will need an extra query to do the export to 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';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文