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
)
;
原文:http://www.cnblogs.com/pcxlj/p/4978146.html