我有一张table如下:
ID | FieldName | FieldValue
--------------------------------
01 | event_name | Event Title
01 | event_cost | 10.00
01 | event_loc | Leeds
02 | event_name | Another Event
02 | event_cost | 15.00
02 | event_loc | London
我想查询并返回如下结果:
Title | Cost | Location
------------------------------------
Event Title | 10.00 | Leeds
Another Event | 15.00 | London
最好的办法是什么?我尝试过使用select查询,但只能返回一个字段值,而且似乎无法加入它们。
5条答案
按热度按时间jutyujz01#
使用条件聚合。
GROUP_CONCAT
如果特定字段名有多个匹配项,则可以使用返回逗号分隔的列表。xfyts7mz2#
尝试此查询:
cclgggtu3#
使用案例
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=940326493ef7b561375953f85f65a4ea
w1jd8yoj4#
您可以执行条件聚合:
svmlkihl5#
用例和聚合: