问题描述
我的需求是存储查询的全部结果
My requirement is to store the entire results of the query
SELECT * FROM document
WHERE documentid IN (SELECT * FROM TaskResult WHERE taskResult = 2429)
到一个 Excel 文件.
to an Excel file.
推荐答案
实现此目的的典型方法是导出为 CSV,然后将 CSV 加载到 Excel 中.
您可以使用任何 MySQL 命令行工具来执行此操作,方法是在 SELECT
语句中包含 INTO OUTFILE
子句:
The typical way to achieve this is to export to CSV and then load the CSV into Excel.
You can using any MySQL command line tool to do this by including the INTO OUTFILE
clause on your SELECT
statement:
SELECT ... FROM ... WHERE ...
INTO OUTFILE 'file.csv'
FIELDS TERMINATED BY ','
有关详细选项,请参阅此链接.
See this link for detailed options.
或者,您可以使用 mysqldump 使用 --tab 选项将转储存储为分隔值格式,请参阅 此链接.
Alternatively, you can use mysqldump to store dump into a separated value format using the --tab option, see this link.
mysqldump -u<user> -p<password> -h<host> --where=jtaskResult=2429 --tab=<file.csv> <database> TaskResult
提示:如果您没有指定绝对路径而是使用诸如 INTO OUTFILE 'output.csv'
或 INTO OUTFILE './output.csv'
之类的内容,它将输出文件存储到由 show variables like 'datadir';
指定的目录.
Hint: If you don't specify an absoulte path but use something like INTO OUTFILE 'output.csv'
or INTO OUTFILE './output.csv'
, it will store the output file to the directory specified by show variables like 'datadir';
.
这篇关于将 Mysql 查询的结果导出到 excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!