开发者

Separate Exports from a MYSQL query

开发者 https://www.devze.com 2023-04-12 00:13 出处:网络
I would like to create separate expor开发者_StackOverflowted 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

I would like to create separate expor开发者_StackOverflowted 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.


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消