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,
));
}
이렇게 할 수 있습니다:
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
스키마와 몇 가지 샘플 데이터를 제공해 주시면 더 적절한 답변을 드릴 수 있습니다.