Matching all values in IN clause(匹配 IN 子句中的所有值)
问题描述
有没有办法确保 IN 子句中的所有值都匹配?
Is there a way to ensure all values in an IN clause are matched?
示例:
我可以将 IN 用作:IN (5,6,7,8).
I can use IN as: IN (5,6,7,8).
我需要它像 AND 一样跨多行工作.
I need it to work like an AND across multiple rows.
更新:我需要这个来列出符合指定参数的 db 公司.公司和分类法是多对多的关系.我正在使用 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 子句中的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:匹配 IN 子句中的所有值
基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
