56,678
社区成员
发帖
与我相关
我的任务
分享
mysql> select * from dict;
+---------+---------+
| dict_id | keyword |
+---------+---------+
| 32321 | pcga |
| 32362 | bp71 |
| 32363 | bp71a |
| 32364 | bp71auc |
| 32365 | bp71ce7 |
+---------+---------+
5 rows in set (0.00 sec)
mysql> select * from dict_to_product;
+------------+---------+
| product_id | dict_id |
+------------+---------+
| 214 | 32321 |
| 215 | 32321 |
| 216 | 32321 |
| 217 | 32321 |
| 216 | 32362 |
| 450 | 32362 |
| 216 | 32363 |
| 450 | 32363 |
+------------+---------+
8 rows in set (0.00 sec)
mysql> select * from product;
+------------+---------------+
| product_id | product_title |
+------------+---------------+
| 214 | 产品1 |
| 215 | 产品2 |
| 216 | 产品3 |
| 217 | 产品4 |
| 450 | 产品5 |
+------------+---------------+
5 rows in set (0.00 sec)
mysql>
mysql> select product_title
-> from (dict_to_product dp inner join product p on dp.product_id=p.product_id)
-> inner join (
-> select dict_id
-> from dict
-> where keyword = 'pcga'
-> or keyword = 'bp71') d on dp.dict_id=d.dict_id
-> group by product_title
-> having count(*)=2;
+---------------+
| product_title |
+---------------+
| 产品3 |
+---------------+
1 row in set (0.00 sec)
mysql>
select product_title
from (dict_to_product dp inner join product p on dp.product_id=p.product_id)
inner join (
select dict_id
from dict
where keyword like '条件1%'
or keyword like '条件2%'
pr keyword like '条件3%') d on dp.dict_id=d.dict_id
group by product_title
having count(*)=3