- 論壇徽章:
- 0
|
本帖最后由 work4seo 于 2019-08-14 11:22 編輯
表結(jié)構(gòu)
payment_detail表包含:id、order_id、serial_id、order_price、coupon_fee這么幾個(gè)字段。
分別是:id、訂單id、支付流水號(hào)、訂單金額、補(bǔ)貼費(fèi)用;
refund_pc表:存儲(chǔ)pc的退款訂單信息
包含id、order_id、serial_id、order_price、refund_price、refund_coupon_fee這么幾個(gè)字段。
分別是:id、訂單id、支付流水號(hào)、訂單金額、退款金額、退回的補(bǔ)貼費(fèi)用;
refund_h5、refund_app表
字段結(jié)構(gòu)與refund_pc完全一致,分別用來存儲(chǔ)h5、app的退款訂單信息。
同一個(gè)訂單,在payment與refund表中的order_id是同一個(gè),但其中的serial_id字段不是同一個(gè)值(每個(gè)涉及到金錢的流水號(hào)都是唯一的)
不知道如何實(shí)現(xiàn)的需求 :
一個(gè)用戶支付完成之后,我就知道了payment_detail.serial_id = 'alipay_3773371a959d61c6831d5b3a0dd996c2'
但是如果這個(gè)用戶發(fā)起退款,因?yàn)椴恢朗窃谀膫(gè)平臺(tái)發(fā)起的退款,按理來說就要分別查3次表。
我要如何在一個(gè)sql里面通過if..else來分別查詢不同的表?
先查一遍refund_pc,沒查到order_id就再去查refund_h5;還沒查到就接著去查refund_app
我希望產(chǎn)出的數(shù)據(jù)是:
payment_detail.order_id as order_id,
payment_detail.serial_id as serial_id,
payment_detail.order_price as order_price,
sum(refund_pc.refund_price,refund_h5.refund_price,refund_app.refund_price) as refund_price,
sum(refund_pc.refund_coupon_fee,refund_h5.refund_coupon_fee,refund_app.refund_coupon_fee) as refund_coupon_fee
在同一個(gè)平臺(tái)中,用戶產(chǎn)生的退款可能是分幾次出現(xiàn)的。
如圖:
微信圖片_20190812150132.png (15.53 KB, 下載次數(shù): 119)
下載附件
2019-08-12 15:02 上傳
|
|