您的位置:程序门 -> db2 -> 数据库开发



初次使用db2,一个sql语句的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


初次使用db2,一个sql语句的问题
发表于:2007-11-12 21:19:13 楼主
大家看这个语句:

select   cabprtyp.id   cableproductpricetypeid,   cabprtyp.pricetype,   cable.cableid,   cable.owner,   cable.anndocno,   cable.validfrom,   product.typeid,   product.model,   product.feature,   product.frommodfea,   product.tomodfea,product.brand,   product.division,   product.description,   product.id   productid  
from   wwprt.price_cn   price,   wwprt.cable_product_join_cn   cabprod,   wwprt.cableproduct_pricetype_join_cn   cabprtyp,   wwprt.product_cn   product,   wwprt.cable_cn   cable  
where   price.overridden   =   'n'   and   price.released   =   'y'  
and   price.cableid   =   cabprod.cableid
and   price.productid   =   cabprod.productid  
and   cabprod.id   =   cabprtyp.cableproductid   and   price.pricetype   =   cabprtyp.pricetype  
and   price.productid   =   product.id  
and   price.cableid   =   cable.cableid
and   not   exists
  (   select   1   from   wwprt.price_cn   price_draft,   wwprt.cable_cn   cable_draft  
where   price.productid   =   price_draft.productid  
and   price.country   =   price_draft.country  
and   price.pricetype   =   price_draft.pricetype  
and   price.distch   =   price_draft.distch  
and   price_draft.cableid   =   cable_draft.cableid   and   cable_draft.status   in   ('01',   '04')   )


子查询中的price是父sql的一个别名,我想知道子查询的作用是什么,好像是同一个表在比较字段,请高人指点。
发表于:2007-11-12 21:45:251楼 得分:0
那个   子查询是   你   想   知道的   ?
发表于:2007-11-12 23:04:492楼 得分:0
price.country       =       price_draft.country   比如这个条件,其实price   和price_draft是同一个表
发表于:2007-11-13 09:43:523楼 得分:0
price得到的应该是一个已经筛选过了的数据集,用这样处理,应该是将price_draft这个表进行筛选(减少数据)
发表于:2007-11-13 17:02:014楼 得分:0
楼上说的有些道理,但是我还是不明白自己和自己比较有什么意义,而且它用的是   select       1       from      



not       exists  

也就是说并不是为了减少数据结果
发表于:2007-11-13 17:12:375楼 得分:0
用select               1               from       和   not       exists       来判断原来的数据集是否和现在的有交集,
发表于:2007-11-13 17:14:016楼 得分:0
应该是判断是否有交集。
发表于:2007-11-13 17:50:327楼 得分:0
你这么一说我就明白了,以前从未这样用过,谢谢了,我再研究一下,看还有没有其他疑问


快速检索

最新资讯
热门点击