首页  >  文章  >  数据库  >  如何将基于某些条件的值从 MySQL 表导出到文件中?

如何将基于某些条件的值从 MySQL 表导出到文件中?

WBOY
WBOY转载
2023-09-15 20:17:05894浏览

如何将基于某些条件的值从 MySQL 表导出到文件中?

我们可以在将数据从 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中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除