欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

oracle 子查询用法 博客分类: DB-Oracle

程序员文章站 2024-03-16 15:03:34
...

 

 

select tor.BACKMONEYSTATUS,tp.PRODUCTID,tpmd.DISCOUNTDETAILID
	,SUM (DECODE (tor.BACKMONEYSTATUS, null, tpmd.ACTUAL_FEE,0, tpmd.ACTUAL_FEE, 0)) unback_many --商品特定支付方式 未回款金额
	,SUM (DECODE (tor.BACKMONEYSTATUS, 1, tpmd.ACTUAL_FEE, 0)) backed_many --商品特定支付方式 已回款金额
	,(
		select sum(tpmd1.ACTUAL_FEE) 
		from t_orders tor1,T_ORDERSDETAIL tord1,T_PAYMENT_DETAIL tpmd1 
		WHERE tor1.ORDERSID=tord1.ORDERSID and tord1.PRODUCTID=tp.productid 
			and tord1.ORDERSID=tpmd1.ORDER_ID and tor1.BACKMONEYSTATUS <>1
		group by tord1.PRODUCTID
	) unback_many_all --商品未回款的总金额
	,(
		select sum(tpmd2.ACTUAL_FEE) 
		from t_orders tor2,T_ORDERSDETAIL tord2,T_PAYMENT_DETAIL tpmd2 
		WHERE tor2.ORDERSID=tord2.ORDERSID and tord2.PRODUCTID=tp.productid 
			and tord2.ORDERSID=tpmd2.ORDER_ID and tor2.BACKMONEYSTATUS =1
		group by tord2.PRODUCTID
	) backed_many_all --商品已回款的总金额
	
from t_orders tor,T_ORDERSDETAIL tord,T_PAYMENT_DETAIL tpmd,T_PRODUCT tp
WHERE  tor.ORDERSID=tord.ORDERSID and tord.PRODUCTID=tp.PRODUCTID 
	and tor.ORDERSID=tpmd.ORDER_ID
	--and tor.BACKMONEYDATE --回款时间
	and tor.FCONFIGID in(1) --城市
	--and tp.BEGINDATE --大于开始时间
	--and tp.ENDDATE --小于结束时间
	and tp.PRODUCTID=23178 
group by tor.BACKMONEYSTATUS,tp.PRODUCTID,tpmd.DISCOUNTDETAILID;