我有以下查询:
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
关于php - Mysql查询CONCAT改变输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28285026/