我們可以在將資料從 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 表匯出到文件中?的詳細內容。更多資訊請關注PHP中文網其他相關文章!