通过属性搜索商品mysql设计

2019-10-24 01:14:29

商品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设置索引

  • 2017-11-01 01:30:45

    解决第三方包内jar包冲突

    这个问题就是因为引入jar包的冲突,这时我们可以在build.gradle中添加如下代码,下方单独的是添加的代码

  • 2017-11-06 01:00:17

    撤销git add

    如何撤销git add,不小心执行了git add . 操作,但是又不能提交所有的文件,因为对应不同的分支,现在怎么样可以将git add 撤销回来

  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.