开发者社区> 问答> 正文

匹配IN子句中的所有值?mysql

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

例:

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

我需要它像AND跨多个行一样工作。

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

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, )); }

展开
收起
保持可爱mmm 2020-05-17 12:16:09 410 0
1 条回答
写回答
取消 提交回答
  • 您可以执行以下操作:

    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 如果您提供架构和一些示例数据,我可以提供一个更相关的答案。来源:stack overflow

    2020-05-17 12:17:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像