我需要在单个镜头中比较具有相同值集的表的多个值,而不在AND
子句中使用多个WHERE
条件。请告诉我任何方法。
select count(1)
from test
where pre_sys_id1 in (select sys_id from test where auto_id = 10)
and pre_sys_id2 in (select sys_id from test where auto_id = 10)
and pre_sys_id3 in (select sys_id from test where auto_id = 10)
and pre_sys_id4 in (select sys_id from test where auto_id = 10)
;
答案 0 :(得分:1)
Select count(1)
from test
where (select sys_id from test where auto_id=10) = all (pre_sys_id1,pre_sys_id2,pre_sys_id3,pre_sys_id4)
或加入
Select count(1)
from test t1
join test t2 on( sys_id= pre_sys_id1 and sys_id= pre_sys_id2 and sys_id= pre_sys_id3 and sys_id= pre_sys_id4)
where t2.auto_id = 10 ;
答案 1 :(得分:1)
您可以尝试:
select count(1)
from test
where (pre_sys_id1, pre_sys_id2, pre_sys_id3, pre_sys_id4)
in (select sys_id, sys_id, sys_id, sys_id from test where auto_id = 10)