我有多选查询,我需要交叉结果
查询:
select pro_id from product_extra_data where type_filed_id='1' and value like '%Intel Xeon%'
intersect
select pro_id from product_extra_data where type_filed_id='3' and value like '%15%'
intersect
select pro_id from product_extra_data where type_filed_id='49' and value like '%8GB%'
intersect
select pro_id from product_extra_data where type_filed_id='50' and value like '%460W%'
intersect
select pro_id from product_extra_data where type_filed_id='47' and value like '%1%'
intersect
select pro_id from product_extra_data where type_filed_id='51' and value like '%5U%'
答案 0 :(得分:1)
MySQL并不支持交叉,但在这个特定的上下文中,您可以通过查询获得相同的结果,如下所示:
select
pro_id
from
product_extra_data
where
(type_filed_id='1' and value like '%Intel Xeon%')
or
(type_filed_id='3' and value like '%15%')
or
(type_filed_id='49' and value like '%8GB%')
or
(type_filed_id='50' and value like '%460W%')
or
(type_filed_id='47' and value like '%1%')
or
(type_filed_id='51' and value like '%5U%')
group by
pro_id
having
count(distinct type_filed_id)=6