简体   繁体   English

通过传递一些常量字符串变量从数据库导出到csv文件

[英]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 : 我想使用以下命令将此详细结果集导出到csv文件中:

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 : 它创建csv文件,格式如下:

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. 如何在生成csv文件时传递这些字符串。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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