1. products_attribute表 保存商品ID和属性ID
2. attribute 保存属性ID和属性值(任意多个)
SELECT GROUP_CONCAT(DISTINCT T2.mydesc separator ' , ')AS desccrption FROM // 把每一行记录连起来并用空格+,分割
(SELECT products_id,
CONCAT_WS(SPACE(1),attribute.attribute_name,products_attribute.attribute_value) AS mydesc
FROM products_attribute
LEFT JOIN attribute
ON attribute.attribute_id = products_attribute.attribute_id) AS T2//表把各种属性种值连起来
group by T2.products_id //结果按商品ID分组.
+----------------------------------------------------------------------------------------------------------------------------------------+
| desccrption |
+----------------------------------------------------------------------------------------------------------------------------------------+
| Price Yes , Weight 1500g , Size 152mm * 130mm * 14mm |
| Size 11 , t 11 , Price 99 , r 11 , Weight 45 , e 11 , p 11 , Size , w 11 , o dsfdf , q 11 , i 56565 , 2trre 11 , u 11 , abc 11 , y 11 |
| abc ww |
| Wang G.H.' Test |
| abc 15 |
+----------------------------------------------------------------------------------------------------------------------------------------+
5 rows in set