Mysql 比较多个列值

Mysql 比较多个列值,mysql,sql,Mysql,Sql,好的,我有一个包含以下数据的表 表过滤器 表说明 如果用户给定了一组过滤器id,我想通过将过滤器id分组来过滤产品,考虑到它们的组id。 select*from filter,其中filter\u id在(1,2)中,filter\u id在(4,5)中。 我之所以在这里使用两次,是因为1,2属于一个filter_组,4,5属于不同的filter_组,表中可能会添加组和过滤器,所以我将根据用户选择使用php生成动态查询 有人能帮我找到这个问题的解决方案吗,提前谢谢你根据你提供的例子,你需要做的子

好的,我有一个包含以下数据的表

表过滤器 表说明 如果用户给定了一组过滤器id,我想通过将过滤器id分组来过滤产品,考虑到它们的组id。
select*from filter,其中filter\u id在(1,2)中,filter\u id在(4,5)中。

我之所以在这里使用两次,是因为1,2属于一个filter_组,4,5属于不同的filter_组,表中可能会添加组和过滤器,所以我将根据用户选择使用php生成动态查询


有人能帮我找到这个问题的解决方案吗,提前谢谢你

根据你提供的例子,你需要做的子查询和你筛选的组一样多,并在这些子查询之间使用
内部联接

SELECT product_id
FROM
  ( SELECT product_id
   FROM filter
   WHERE filter_id IN (1,
                       2)) group1 // Here you select white or black products 
INNER JOIN
  ( SELECT product_id
   FROM filter
   WHERE filter_id IN (4)) group2 // here products with Formal style
using(product_id) // Here both

根据您提供的示例,您需要执行与组一样多的子查询,并在这些子查询之间过滤和使用
内部联接

SELECT product_id
FROM
  ( SELECT product_id
   FROM filter
   WHERE filter_id IN (1,
                       2)) group1 // Here you select white or black products 
INNER JOIN
  ( SELECT product_id
   FROM filter
   WHERE filter_id IN (4)) group2 // here products with Formal style
using(product_id) // Here both

这个问题对我很有用:

select
..
......

where filter.product_id in
  (select a.product_id from filter a where a.filter_id in (1,2))
AND filter.product_id in 
  (select a.product_id from filter a where a.filter_id in(4))

这个问题对我很有用:

select
..
......

where filter.product_id in
  (select a.product_id from filter a where a.filter_id in (1,2))
AND filter.product_id in 
  (select a.product_id from filter a where a.filter_id in(4))

您使用的是SQL Server还是MySQL?请适当地标记问题。请用表格命名您的表格示例names@MarcusH进行了更改请将预期输出作为“过滤产品,如根据其组id对过滤产品进行分组”不清楚我是否需要过滤器为黑色或白色且样式正式的产品id。您使用的是SQL Server还是MySQL?请适当地标记问题。请用表格命名您的表格示例names@MarcusH进行了更改请将预期输出作为“过滤产品,如根据其组id对过滤产品进行分组”不清楚我是否需要过滤器为黑色或白色且样式正式的产品id。我是这方面的初学者,但你能帮助我将此查询集成到完整查询中吗?从oc_产品中选择不同的oc_产品id、oc_产品图像、oc_产品名称、oc_产品选项、oc_产品选项、oc_产品价格,oc_产品至类别,oc_产品选项,oc_review$from where oc_product_option.product_id=oc_product.product_id和oc_product_to_category.category_id=$category_id和oc_product_to_category.product_id=oc_product.product_id=oc_product.product_id在这方面我是个新手,但你能帮我将这个查询集成到完整的查询中吗?选择不同的oc_product.product_id,oc_product.image、oc_product.name、oc_product_option.option_id、oc_product.price FROM oc_product、oc_product_to_category、oc_product_option、,oc_review$其中oc_product_option.product_id=oc_product.product_id和oc_product_to_category.category_id=$category_id和oc_product_to_category.product_id=oc_product.product_id