oracle subquery usage

 

 

select tor.BACKMONEYSTATUS,tp.PRODUCTID,tpmd.DISCOUNTDETAILID
	,SUM (DECODE (tor.BACKMONEYSTATUS, null, tpmd.ACTUAL_FEE,0, tpmd.ACTUAL_FEE, 0)) unback_many --The amount of unreturned payment for the specific payment method of the product
	,SUM (DECODE (tor.BACKMONEYSTATUS, 1, tpmd.ACTUAL_FEE, 0)) backed_many --The amount returned by the product-specific payment method
	,(
		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 -- the total amount of unpaid items
	,(
		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 -- the total amount of the item that has been refunded
	
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 --payback time
	and tor.FCONFIGID in(1) -- city
	--and tp.BEGINDATE -- greater than start time
	--and tp.ENDDATE -- less than the end time
	and tp.PRODUCTID=23178
group by tor.BACKMONEYSTATUS,tp.PRODUCTID,tpmd.DISCOUNTDETAILID;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326496472&siteId=291194637