Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)
问题描述
我的需求是存储查询的全部结果
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 Mysql 查询的结果导出到 excel?
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
