mysql商品表
itemid int(11) //商品ID
itemname varchar(255) //商品名称
created int(10) //发布时间商品属性表结构
itemid int (11) //商品ID
propertyid int(11) //属性ID,冗余字段,
propertyvalueid int(11) //属性值ID
要求
类似于淘宝的商品搜索过滤
自己写了一个sql,过滤值为7和20,SELECT COUNT(1) AS cnt,b.itemid,a.itemname FROM item a INNER JOIN item_property b ON a.itemid = b.itemid WHERE b.`propertyvalueid` IN(7,20) GROUP BY itemid ORDER BY CREATED DESC;问题:
上面的这个sql,如何建立索引呢
itemid int(11) //商品ID
itemname varchar(255) //商品名称
created int(10) //发布时间商品属性表结构
itemid int (11) //商品ID
propertyid int(11) //属性ID,冗余字段,
propertyvalueid int(11) //属性值ID
要求
类似于淘宝的商品搜索过滤
自己写了一个sql,过滤值为7和20,SELECT COUNT(1) AS cnt,b.itemid,a.itemname FROM item a INNER JOIN item_property b ON a.itemid = b.itemid WHERE b.`propertyvalueid` IN(7,20) GROUP BY itemid ORDER BY CREATED DESC;问题:
上面的这个sql,如何建立索引呢
搜索过滤
应该propertyid,propertyvalueid两个字段同时使用吧
FROM item a INNER JOIN item_property b ON a.itemid = b.itemid
WHERE b.`propertyvalueid` IN(7,20)
GROUP BY itemid
ORDER BY CREATED DESC;你的这个语句会报语法错误吧。 建议先把语句写正确,然后再找出优化的方法。
如何propertyvalueid唯一的话,是可以不同时使用的,propertyvalueid的作用就是文本字典,
是正确的,我在sqlyog中测试正确后,优化的时候,才提出的问题