答案 0 :(得分:1)
您可以使用group by
和having
:
select object_id
from t
group by object_id
having sum(case when format_id = 1 then 1 else 0 end) > 0 and
sum(case when format_id = 3 then 1 else 0 end) > 0 and
sum(case when format_id = 11 then 1 else 0 end) > 0 and
sum(case when format_id = 12 then 1 else 0 end) > 0 and
sum(case when format_id = 10 then 1 else 0 end) = 0;
每个条件都会测试其中一个format_id
。 > 0
表示至少有一个分配给object_id
。 = 0
表示没有分配任何内容。