有没有办法确保IN子句中的所有值都匹配?

例子:

我可以用as:IN (5,6,7,8).

我需要它在多行中像AND一样工作.

UPDATE:

public function actionFilters($list)
{
    $companies = new CActiveDataProvider('Company', array(
        'criteria' => array(
            'condition'=> 'type=0',
            'together' => true,
            'order'=> 'rating DESC',
            'with'=>array(
            'taxonomy'=>array(
                'condition'=>'term_id IN ('.$list.')',
                )
            ),
        ),
    ));
    $this->render('index', array(
        'companies'=>$companies,
    ));
}

推荐答案

你可以这样做:

select ItemID
from ItemCategory
where CategoryID in (5,6,7,8) <-- de-dupe these before building IN clause
group by ItemID
having count(distinct CategoryID) = 4 <--this is the count of unique items in IN clause above

如果你提供你的模式和一些样本数据,我可以提供一个更相关的答案.

SQL Fiddle Example

Mysql相关问答推荐

MYSQL子查询

MySQL查询基于上次访问时间戳更新用户的问题

为什么MySQL派生条件下推优化不起作用

MySQL工作台的编码问题

获取连续11天未考勤的员工

是否可以使用 IN 或 NOT IN 从没有关联其他表中任何行的表中返回这些名称?

看不懂mysql自左连接查询

获取 TEXT 类型行的百分比

将sql查询转换为sequelize

如何在更新语句中使用多个子字符串函数?

如何在任何连续范围内获得最大值

Select 多列但仅按 1 列分组

Golang Gorm没有从关联表中检索数据

为什么 ORDER BY 'id' 'desc' 不返回语法错误?

如何在mysql select查询中获取两个日期之间的日期列表

有没有办法在 Zend Framework 1.5 中执行INSERT...ON DUPLICATE KEY UPDATE?

重新加载 .env 变量而不重新启动服务器(Laravel 5,共享主机)

安装 mysql-python (Windows)

如何让mysql自动启动? (仅限 linux-cli)

MySQL中的base64编码