我们可以在将数据从 MySQL 表导出到文件时使用 WHERE 子句中的条件。可以通过示例来理解 –
示例
假设我们从表“Student_info”中有以下数据 –
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.07 sec)
假设我们要导出 id 值大于 120 的记录,那么以下查询会将此类记录从“Student_info”表导出到“Stuednt4.CSV”文件中 –
mysql> Select * from student_info WHERE id > 120 into outfile 'C:/mysql/bin/mysql-files/student4.csv' Fields terminated by ','; Query OK, 4 rows affected (0.16 sec)
上面的查询会将以下值导出到 Student4.CSV 文件中 –
125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers原文来自:www.php.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容