我谈谈我的理解: 1.select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id 3个表做关联查询,把符合条件的数据查出来,假设是记录集sss2.Select * from sale_item b where order_no ='3' and not exists (select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id))(注:假设 select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id得出的结果集是sss) 从sale_item表中根据条件order_no='3'并且不在数据集sss中的记录集,得出的记录集假设叫kkk3.Select distinct order_no From sale_item a Where order_no<>'3' and not exists kkk 将sale_item表中根据条件order_no<>'3'并且不在记录集kkk中的(distinct)不重复记录检索出,得到结果集
看了看,另外写一个 Select distinct a.order_no From sale_item a,sale_item b where a.order_no<>'3'and b.order_no<>'3'and a.order_no<> b.order_no and a.prod_id=b.prod_id原文好像是要找出表中order_no自身order_no<>'3'而且通过prod_id与他关联的表中的其他数据里也都是order_no<>'3'的数据
1.select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id
3个表做关联查询,把符合条件的数据查出来,假设是记录集sss2.Select * from sale_item b where order_no ='3' and not exists
(select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id))(注:假设 select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id得出的结果集是sss)
从sale_item表中根据条件order_no='3'并且不在数据集sss中的记录集,得出的记录集假设叫kkk3.Select distinct order_no From sale_item a Where order_no<>'3' and not exists kkk
将sale_item表中根据条件order_no<>'3'并且不在记录集kkk中的(distinct)不重复记录检索出,得到结果集
Select distinct a.order_no
From sale_item a,sale_item b
where a.order_no<>'3'and b.order_no<>'3'and a.order_no<> b.order_no and
a.prod_id=b.prod_id原文好像是要找出表中order_no自身order_no<>'3'而且通过prod_id与他关联的表中的其他数据里也都是order_no<>'3'的数据
我上面写的那段sql的意义和原文不同,呵呵
请见谅
三个表分别从原表sale_item中取满足条件的数据形成临时表
然后这些临时表再拼接组成新的临时表..这样可以实现在单一的表中查询多条件的数据
2.带有exists谓词的子查询不返回任何数据,只产生逻辑真值“true”或逻辑假值“false”.
3.相关子查询,从内查询一步步的向外面的查询进行分析。
=======================================================
你肯定有示例数据库,根据我上面的解释,耐心的一步步的分析,繁琐的内容一经剖析,就散了。
相信你能行的!