Mysql 查询 CONCAT 更改输出
Mysql query CONCAT change the output
我有以下查询:
mysql> select (select m.delay from messages m order by message_id desc limit 1) as Delay, s.min_delay, s.max_delay from statistics s order by s.date_hour desc limit 1;
+-------+-----------+-----------+
| Delay | min_delay | max_delay |
+-------+-----------+-----------+
| 10 | 7.00 | 12.00 |
+-------+-----------+-----------+
1 row in set (0.00 sec)
这很好。但是我需要得到以下格式的结果:
Delay=10 Min_Delay=7.00 Max_Delay=12.00
我可以使用 concat 来做到这一点吗?
通常,您会在应用程序层进行转换。但是,如果您想使用 concat()
:
,可以在 MySQL 中执行此操作
select concat_ws(' ',
concat('Delay=', (select m.delay from messages m order by message_id desc limit 1)),
concat('Min_Delay=', s.min_delay),
concat('Max_Delay=', s.max_delay)
)
from statistics s
order by s.date_hour desc
limit 1
我有以下查询:
mysql> select (select m.delay from messages m order by message_id desc limit 1) as Delay, s.min_delay, s.max_delay from statistics s order by s.date_hour desc limit 1;
+-------+-----------+-----------+
| Delay | min_delay | max_delay |
+-------+-----------+-----------+
| 10 | 7.00 | 12.00 |
+-------+-----------+-----------+
1 row in set (0.00 sec)
这很好。但是我需要得到以下格式的结果:
Delay=10 Min_Delay=7.00 Max_Delay=12.00
我可以使用 concat 来做到这一点吗?
通常,您会在应用程序层进行转换。但是,如果您想使用 concat()
:
select concat_ws(' ',
concat('Delay=', (select m.delay from messages m order by message_id desc limit 1)),
concat('Min_Delay=', s.min_delay),
concat('Max_Delay=', s.max_delay)
)
from statistics s
order by s.date_hour desc
limit 1