商品detail表
包含了商品的id,和扩展字段
商品属性表
属性是可以动态扩展的,问题:属性是搜索条件 问:请展示出 材质为塑料 防水为YES,颜色为绿色的商品详细信息,按照sort_filed排序
sql编写:
SELECT gd.goods_id, gd.sort_filed FROM ( SELECT goods_id FROM `goods_attr` WHERE ( attr_name = '材质' AND attr_value = '塑料' ) OR ( attr_name = '颜色' AND attr_value = '绿色' ) OR ( attr_name = '防水' AND attr_value = 'YES' ) GROUP BY goods_id HAVING COUNT( goods_id ) = 3 ) attr LEFT JOIN goods_detail gd ON attr.goods_id = gd.goods_id ORDER BY gd.sort_filed
继续优化将attr_name 和attr_value设置索引