gpt4 book ai didi

mysql - 将产品属性表与产品表连接起来以显示产品

转载 作者:可可西里 更新时间:2023-11-01 06:28:52 26 4
gpt4 key购买 nike

我有三个表用于列出具有产品属性的产品

产品表带有虚拟数据

enter image description here

enter image description here

Product_Attributes 带有虚拟数据

enter image description here

enter image description here

属性与虚拟数据

enter image description here

enter image description here

Kespersky 防病毒软件 (productid = 1) 没有属性,但 iPhone (productid =2) 有两个适用的属性,内存和分辨率都在 Attribute 表中,其值存储在 >Product_Attribute 表。

我如何连接这些表格以显示/显示具有相应属性的产品?

编辑

我需要将这些产品显示为

enter image description here

最佳答案

以下内容适用于任意数量的属性:

select product.productId, product.name,
group_concat(concat(attr.attributeName, ":", pa.attributeValue))
from product
left outer join product_attributes pa
on (pa.productId = product.productId)
left outer join attributes attr
on (attr.attributeId = pa.attributeId)
group by product.productId, product.name

关于mysql - 将产品属性表与产品表连接起来以显示产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30817434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com