匹配IN子句中的所有值 [英] Matching all values in IN clause

查看:75
本文介绍了匹配IN子句中的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to ensure all values in an IN clause are matched?

示例:

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

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

I need it to work like an AND across multiple rows.

更新: 我需要它列出适合指定参数的数据库公司.公司和分类法之间存在很多关系.我正在使用Yii框架.这是我的控制器的代码:

UPDATE: I need this to list companies from db that fit specified parameters. Companies and taxonomy are MANY TO MANY relation. I'm using Yii framework. And this is the code of my controller:

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

如果您提供架构和一些示例数据,我可以提供一个更相关的答案.

If you provide your schema and some sample data, I can provide a more relevant answer.

SQL小提琴示例

这篇关于匹配IN子句中的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆