我們可以在將數據從 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
登錄后復制
以上就是如何將基于某些條件的值從 MySQL 表導出到文件中?的詳細內容,更多請關注www.92cms.cn其它相關文章!