select *
from SpeComAud_TstLab c
join SpeComAud_Ppcn b on c.sid=b.sid
join SpeComAud_Sale a on c.sid=a.sid
where a.sPatternno='A' and b.sppono='B' and (
(c.sTestItemNo='AB' and c.sTestDescpt='经向' and sTestResult=0.6)
or
(c.sTestItemNo='BD' and c.sTestDescpt='一次' and sTestResult=50)
)
from SpeComAud_TstLab c
join SpeComAud_Ppcn b on c.sid=b.sid
join SpeComAud_Sale a on c.sid=a.sid
where a.sPatternno='A' and b.sppono='B' and (
(c.sTestItemNo='AB' and c.sTestDescpt='经向' and sTestResult=0.6)
or
(c.sTestItemNo='BD' and c.sTestDescpt='一次' and sTestResult=50)
)
比如我要查符合sPatternno=A,sppono=B,
sTestItemNo=AB,sTestDescpt=经向,sTestResult=0.6,
sTestItemNo=ZZ,sTestDescpt=一次,sTestResult=50
的纪录,因为在SpeComAud_TstLab表中,没有sid测试过ZZ项目,所以查询结果应该为空。
如果按照zjcxc(邹建)大哥的方法查找的话,会把符合sPatternno=A,sppono=B,
sTestItemNo=AB,sTestDescpt=经向,sTestResult=0.6的语句查找出来。
sTestItemNo=AB,sTestDescpt=经向,sTestResult=0.6,
sTestItemNo=BD,sTestDescpt=一次,sTestResult=50
两个条件同时满足?,那是永远没记录的.
你是想
sTestItemNo=AB,sTestDescpt=经向,sTestResult=0.6,
sTestItemNo=BD,sTestDescpt=一次,sTestResult=50
两个条件同时满足?,那是永远没记录的.
======================================================================
没错,我要的就是这种结果。
昨天晚上想了一种方法:
select * from SpeComAud_Sale a,SpeComAud_Ppcn b where a.sid=b.sid and a.sPatternno='A' and b.sppono='B' and a.sid in (select sid from SpeComAud_TstLab where sTestItemNo=AB and sTestDescpt=经向 and sTestResult=0.6) and a.sid in (select sid from SpeComAud_TstLab where sTestItemNo=BD and sTestDescpt=一次 and sTestResult=50)
就是不知道运行效率怎么样。
zjcxc(邹建) 大哥,我的题没讲清楚,我并不是要表3中的数据,我要的只是表1、表2中的数据,表3只是作为判断条件。
不知道我这次讲得清楚不清楚,zjcxc(邹建) 大哥还有什么效率更高的查寻方法吗?
select * from SpeComAud_Sale a
join SpeComAud_Ppcn b on a.sid=b.sid
where a.sPatternno='A' and b.sppono='B'
and a.sid in (select sid from SpeComAud_TstLab where sTestItemNo='AB' and sTestDescpt='经向' and sTestResult=0.6)
and a.sid in (select sid from SpeComAud_TstLab where sTestItemNo='BD' and sTestDescpt='一次' and sTestResult=50)
select * from SpeComAud_Sale a
join SpeComAud_Ppcn b on a.sid=b.sid
where a.sPatternno='A' and b.sppono='B'
and exists(select 1 from SpeComAud_TstLab where sid=a.sid and sTestItemNo='AB' and sTestDescpt='经向' and sTestResult=0.6)
and exists(select 1 from SpeComAud_TstLab where sid=a.sid and sTestItemNo='BD' and sTestDescpt='一次' and sTestResult=50)