我有以下查询:
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吗?
答案 0 :(得分:2)
通常,您会在应用程序层进行转换。但是,如果要使用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