简体   繁体   中英

export to csv file from database by passing some constant string variables

Let's say my database table structure is like :

he     haddress hage   she        saddress     sage
Sam      USA    25   Jenny      germany     21
John     UK     32   Anne       france      29
keith    USA    27   nicole     france      21

I want to export this aboce result set into a csv file using this command :

select he, haddress, hage, she, saddress, sage into outfile '/tmp/test1.csv' 
fields terminated by ','
lines terminated by '\n' from table_name;

it creates the csv file as following format :

Sam,USA,25,Jenny,germany,21
John,UK,32,Anne,france,29
keith,USA,27,nicole,france,21

now I want the above as below :

Sam,address,USA,age,25,knows,Jenny,address,germany,age,21
.....
.....
.....

how to pass these string while generating the csv file.

select he, 'address', haddress, 'age',  hage, 'knows', she, 'address', saddress, 'age' sage into outfile '/tmp/test1.csv' 
fields terminated by ','
lines terminated by '\n' from table_name;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM