SQL 查询拼接字段输出 CSV 格式


mysql> select * from capacity;
+----+----------+---a---------+---------------------+
| id | capacity | date       | time                |
+----+----------+------------+---------------------+
|  1 |      180 | 2019-10-26 | 2019-10-30 09:34:48 |
|  2 |      190 | 2019-10-27 | 2019-10-30 09:34:48 |
|  3 |      200 | 2019-10-28 | 2019-10-30 09:34:48 |
|  4 |      210 | 2019-10-29 | 2019-10-30 09:34:48 |
|  5 |      224 | 2019-10-30 | 2019-10-30 09:34:48 |
+----+----------+------------+---------------------+
5 rows in set (0.00 sec)

mysql> SELECT         CONCAT(capacity,',',time) FROM capacity;
+---------------------------+
| CONCAT(capacity,',',time) |
+---------------------------+
| 180,2019-10-30 09:34:48   |
| 190,2019-10-30 09:34:48   |
| 200,2019-10-30 09:34:48   |
| 210,2019-10-30 09:34:48   |
| 224,2019-10-30 09:34:48   |
+---------------------------+
5 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

想导出 csv 文件,重定向即可。