下面的选择概念可以转换为sql select吗?
select S_ID from table1 where S_Type = TYPE and all S_ID in (select S_ID from table2)
其概念如下:
item1,item2和item3应该都在其中(从表中选择ITEMS)
如果所有S_ID都在其中,则select语句仅应返回一行(从表2中选择S_ID)
答案 0 :(得分:1)
您需要先放置比较运算符
select S_ID from table1 where S_ID = ALL (select S_ID from table2)
答案 1 :(得分:1)
如果要让S_ID
的所有项都位于第二个表中,请使用聚合
select t1.S_ID
from table1 t1
where t1.S_Type = 'TYPE' and
t1.item in (select t2.item from table2 t2)
group by S_ID
having count(distinct t1.item) = (select count(distinct t2.item) from table2 t2);