从 MYSQL 查询中分离导出

发布于 2024-12-08 19:45:34 字数 535 浏览 0 评论 0原文

我想为表中不同类型的动物创建单独的导出报告。我可以单独编写这些报告,但是我有 200 多种不同的动物类型,因此运行 200 个单独的查询是不切实际的。

ANIMAL_TABLE

    AnimalName
    -----------
    CAT 
    DOG
    MOUSE
    HORSE

我基本上想运行一个类似的查询,

SELECT * INTO OUTFILE '/tmp/ANIMAL-NAME.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE 1

但有 4 个 CSV 文件而不是一个,实际上动物类型的每次更改都会创建一个新文件

CAT.csv 
DOG.csv
MOUSE.csv
HORSE.csv

任何帮助将不胜感激。

I would like to create separate exported reports for the different types of animal I have in my table. I can write these reports separately, however I have over 200 different animal types and therefore running 200 separate queries is impractical.

ANIMAL_TABLE

    AnimalName
    -----------
    CAT 
    DOG
    MOUSE
    HORSE

I basically would like to run a similar query to

SELECT * INTO OUTFILE '/tmp/ANIMAL-NAME.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE 1

but have 4 CSV files instead of one, effectively every change in animal type creates a new file

CAT.csv 
DOG.csv
MOUSE.csv
HORSE.csv

Any help would be appreciated.

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

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

发布评论

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

评论(1

浪漫人生路 2024-12-15 19:45:34
SELECT * INTO OUTFILE '/tmp/ANIMAL-HORSE.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE animal_name LIKE 'horse'
SELECT * INTO OUTFILE '/tmp/ANIMAL-HORSE.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM ANIMAL_TABLE WHERE animal_name LIKE 'horse'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文