【发布时间】:2019-10-02 17:02:40
【问题描述】:
我有一个页面显示来自 DB 的所有汽车。 我有两个过滤器,都是多选过滤器。 例如
过滤器 1 - 颜色
红、绿、蓝
过滤器 2 - 品牌
宝马、本田、现代
我已经完成了下面的查询
Select * from cars
JOIN term_car_relationships
ON cars.id = term_cars_relationships.car_id
WHERE term_cars_relationships.term_id in (6,2,3)
GROUP BY cars.id
在上面的查询term_id
6 = 蓝色(颜色)
2 = 绿色(颜色)
3 = BNW(品牌)
但是通过上述查询,我将获得所有具有蓝色或绿色或宝马品牌的汽车 但是如何改变我得到蓝色或绿色的宝马。
我有 3 个处理这些类别的表。
分类表
taxonomy_id | taxonomy_title
1 | Color
2 | Brand
术语列表
term_id | term_name | taxonomy_id
1 | Blue | 1
2 | Red | 1
3 | BMW | 2
4 | Honda | 2
term_cars_relationships 表
term_id | car_id
1 | 1
1 | 2
2 | 3
【问题讨论】:
-
除非数据集很大,否则考虑将整个数据集加载到一些 json 中并在那里处理过滤。