有没有办法确保IN子句中的所有值都匹配?
例:
我可以使用IN作为:IN (5,6,7,8).
我需要它像AND跨越多行一样工作.
更新: 我需要这个来列出符合指定参数的db公司.公司和分类学有很多关系.我正在使用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,
));
}
Run Code Online (Sandbox Code Playgroud)
Red*_*ter 65
你可以这样做:
select ItemID
from ItemCategory
where CategoryID in (5,6,7,8)
group by ItemID
having count(distinct CategoryID) = 4 <--this number is # of unique items in IN clause
Run Code Online (Sandbox Code Playgroud)
如果您提供架构和一些示例数据,我可以提供更相关的答案.
SELECT ItemID
FROM ItemCategory
WHERE (
(CategoryID = 5) OR
(CategoryID = 6) OR
(CategoryID = 7) OR
(CategoryID = 8)
)
GROUP BY ItemID
HAVING COUNT(DISTINCT CategoryID) = 4
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21211 次 |
| 最近记录: |