我們可以在將數(shù)據(jù)從 MySQL 表導(dǎo)出到文件時(shí)使用 WHERE 子句中的條件。可以通過(guò)示例來(lái)理解 –
示例
假設(shè)我們從表“Student_info”中有以下數(shù)據(jù) –
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)
登錄后復(fù)制
假設(shè)我們要導(dǎo)出 id 值大于 120 的記錄,那么以下查詢會(huì)將此類記錄從“Student_info”表導(dǎo)出到“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)
登錄后復(fù)制
上面的查詢會(huì)將以下值導(dǎo)出到 Student4.CSV 文件中 –
125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers
登錄后復(fù)制
以上就是如何將基于某些條件的值從 MySQL 表導(dǎo)出到文件中?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!