我有一个相当复杂的问题(至少对我来说)
我有以下表格结构
| id | roomtype | roomno | feature
| 1 | STDK | 11 | BT
| 2 | STDK | 11 | AE
| 3 | STDK | 22 | SMK
| 4 | STDK | 22 | BT
| 5 | STDT | 33 | NONSMK
我想要这样的输出
Type: STDK - RoomNo: 11 - Features: BT, AE
Type: STDK - RoomNo: 22 - Features: SMK, BT
Type: STDT - RoomNo: 33 - Features: NONSMK
可能不是那么复杂,但我听不懂...
最佳答案
这显示了您正在寻找的结果...但是我不喜欢在查询中格式化结果的想法!
select
concat("Type: ", roomtype,
" - RoomNo: ", roomno,
" - Features: ", group_concat(feature order by feature separator ', '))
as result
from t1
group by roomtype, roomno
这是工作中的example
关于mysql - 具有多个数字的MySQL DB显示为行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9188458/