首页 > 其他 > 详细

orcal使用not exists去重

时间:2015-11-19 18:11:07      阅读:481      评论:0      收藏:0      [点我收藏+]

1.t表是f表的子表,现在要从f表中去掉t表中的数据

select f.* from f where not exists t

2.实例

select f.* from
(select shopsellst.Shopsellheadid,shopsell.shoppeid,shopsell.selldate,shopsell.hykh,shopsellst.productid,pmd.productname,shopsellst.formerretailprice,shopsellst.factretailprice,
       sum(shopsellst.Quantity) Quantity,sum(shopsellst.Factretailmoney) Factretailmoney
       from goodbabyqjd.shopsellst
       inner join goodbabyqjd.shopsell on shopsell.shopsellheadid=shopsellst.shopsellheadid and shopsell.cancelsign=‘N‘
       left join goodbabyqjd.productmaindossier pmd on pmd.drpproductid=shopsellst.productid and pmd.cancelsign=‘N‘
       where shopsellst.cancelsign=‘N‘ and shopsell.SELLSTATEID in (‘01‘,‘02‘)
             and shopsell.selldate between to_date(‘2015-02-01‘,‘YYYY-MM-DD‘) and to_date(‘2015-02-28‘,‘YYYY-MM-DD‘)
             and shopsell.gbkh=‘2‘
             and length(trim(shopsell.hykh))>0
             and shopsellst.productid<>‘JFDK‘
       group by shopsellst.Shopsellheadid,shopsell.shoppeid,shopsell.selldate,shopsell.hykh,shopsellst.productid,pmd.productname,shopsellst.formerretailprice,shopsellst.factretailprice
) f
where not exists
 (select a.shopsellheadid,a.shopid,a.shelldate,a.membercardid,b.PRODUCTID,b.PRODUCTNAME, 
b.forerretailprice,b.factretailprice,b.count,b.factretailmoney
from CRM_SHOP_SELL a,crm_shop_sell_list b
where a.shopsellheadid=b.shopsellheadid
 and a.shelldatetime>=‘2015-02-01‘
 and a.shelldatetime<‘2015-03-01‘
 and f.productid=b.productid and f.Shopsellheadid=a.shopsellheadid
 group by   a.shopsellheadid,a.shopid,a.shelldate,a.membercardid,b.PRODUCTID,b.PRODUCTNAME, 
b.forerretailprice,b.factretailprice,b.count,b.factretailmoney
 )
 ;

orcal使用not exists去重

原文:http://www.cnblogs.com/pcxlj/p/4978146.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!