52

句内のすべての値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,
    ));
}
4

2 に答える 2

83

次のようなことができます。

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

スキーマといくつかのサンプル データを提供していただければ、より適切な回答を提供できます。

SQL フィドルの例

于 2012-07-24T17:22:50.760 に答える
5
 SELECT ItemID
     FROM ItemCategory
        WHERE (
               (CategoryID = 5) OR 
               (CategoryID = 6) OR 
               (CategoryID = 7) OR 
               (CategoryID = 8)
              )
     GROUP BY ItemID
 HAVING COUNT(DISTINCT CategoryID) = 4
于 2012-07-24T17:38:51.173 に答える