Mysql INTERSECT无法正常工作

时间:2016-01-31 09:53:30

标签: mysql

我有多选查询,我需要交叉结果
查询:



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%'

1 个答案:

答案 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