【发布时间】:2021-08-28 22:29:23
【问题描述】:
我在使用 mysql 创建查询时遇到问题,我有以下行:
我希望结果是这样的:
[
{
"value": "VERTICAL_DESIGN_SOFT_MATERIAL",
"images": [
{
"color": "white",
"image": "http://localhost/white.png"
},
{
"color": "black",
"image": "http://localhost/black.png"
},
{
"color": "gray",
"image": "http://localhost/gray.png"
}
]
},
{
"value": "VERTICAL_DESIGN_HARD_MATERIAL",
"images": [
{
"color": "blanco",
"image": "http://localhost/blanco.png"
},
{
"color": "black",
"image": "http://localhost/black.png"
},
{
"color": "gray",
"image": "http://localhost/gray.png"
},
{
"color": "azul",
"image": "http://localhost/o_azul.png"
}
]
}
]
我将其显示为 json,因为我认为这描述了我需要的内容,我想在字段中对颜色和图像进行分组以访问该行,我尝试使用 group by 但我无法得到它,
我试过这样的:
SELECT v_ebt,colors,image FROM `am_mm_baggage_select_2` group by colors, image
你能帮帮我吗?
问候 马里奥
【问题讨论】:
-
数据显示问题一般在应用代码中解决
-
请显示您尝试的 sql ...
-
你的样本数据和想要的结果真的没有任何关系,所以不清楚你想做什么。 作为文本表 的示例数据和所需结果会非常有帮助。另外,要清楚你想要的格式。您是否专门寻找 JSON 结果集?
-
@Dri372 我用这个:SELECT v_ebt,colors,image FROM
am_mm_baggage_select_2group by colours, image -
嗨@GordonLinoff 我不是在寻找 json 结果,它只是为了解释我想如何在字段或 var 中获取这些字段附加颜色和图像