0
===========================
= id = model_id = property =
===========================
= 14 = 1        = 1       =
===========================
= 15 = 1        = 3       =
===========================
= 16 = 2        = 1       =

上記のようなテーブルがあり、プロパティが 1 AND 3 に等しい model_ids のみを選択したい

やり方を教えていただけると嬉しいです

4

4 に答える 4

2

あなたがこれを望んでいるように聞こえます:

select model_id
from yourtable
where property in (1, 3)
group by model_id
having count(*) > 1;

デモで SQL Fiddle を参照してください

または、次を使用できます。

select model_id
from yourtable t1
where property = 1
  and exists (select model_id
              from yourtable t2
              where t1.model_id = t2.model_id
                and property = 3)

デモで SQL Fiddle を参照してください

于 2012-11-06T11:43:22.783 に答える
0

これを試して:

SELECT DISTINCT model_ids 
FROM tableName 
WHERE property in (1,3) 
GROUP BY model_ids 
HAVING COUNT( DISTINCT property ) = 2
于 2012-11-06T11:38:50.927 に答える
0

IN次の句を使用できます。

SELECT `model_id`
  FROM `table`
  WHERE `property` IN (1, 3)
于 2012-11-06T11:21:38.553 に答える
0
select model_ids from yourtable where property in(1,3)
于 2012-11-06T11:22:09.037 に答える