多表关联实现左连接

表A,表B,表C,表D,ABC实现关联,并C与D实现左连接

select * from A,B,C left join D on C.id=D.id


例子:

select * from
(select distinct pcc.PAY_CHANNEL_ID,   z.IDENTITY_ID, x.API_TYPE, z.CREATE_TIME,Z.LAST_UPDATE_TIME,  
z.PAY_METHOD,x.MERCHANT_ACCOUNT,m.PRODUCT_NAME,X.CUSTOMER_ORDER_ID,z.LAST_CARD_NO,z.BANK,X.YB_ORDER_ID,X.AMOUNT ,
m.UPDATE_TIME,X.IDENTITY_TYPE,Z.PHONE,Z.STATUS,Z.ERROR_MSG,  rownumber() over(ORDER BY m.UPDATE_TIME DESC )
as rowid
FROM EWALLET.PAYAPI_TRANSACTION_ORDER as x ,EWALLET.PAY_BUSIN_ORDER as m ,EWALLET.PAYAPI_PAYMENT_ORDER as z left join
EWALLET.PAY_CARD_CHANNEL as pcc on  z.CHANNEL_ID=pcc.PAY_CARD_CHANNEL_ID  where 1=1 and z.PAYAPI_TRANSACTION_ORDER_ID=x.ID and  m.ORDER_ID=x.YB_ORDER_ID
and CUSTOMER_ORDER_ID in ('Y20131224112500512998B72')  )as a
where a.rowid >= 1 AND a.rowid <=10 


表A,表B ,条件不同,但是结果字段相同

(select * from A,B where time = 1 and A.id =B.id)

union

(select * from A,B where time = 2 and A.id =B.id)

但是具体排序是按照hour_amount从小到大排序


例子:

(select count(*) as hour_ci ,sum(houra.ORDER_AMOUNT) as hour_amount from EWALLET.PAY_BUSIN_ORDER as houra where 1=1  and houra.TRADER_ID like '%YB0111231231313%' and houra.UPDATE_TIME <='1387468800'  and houra.UPDATE_TIME >='1387461600' )
union 
(select count(*) as hour_ci ,sum(houra.ORDER_AMOUNT) as hour_amount from EWALLET.PAY_BUSIN_ORDER as houra where 1=1  and houra.TRADER_ID like '%YB0111231231313%' and houra.UPDATE_TIME <='1387461600'  and houra.UPDATE_TIME >='1387454400')
union
(select count(*) as hour_ci ,sum(houra.ORDER_AMOUNT) as hour_amount from EWALLET.PAY_BUSIN_ORDER as houra where 1=1  and houra.TRADER_ID like '%YB0111231231313%' and houra.UPDATE_TIME <='1387454400'  and houra.UPDATE_TIME >='1387447200' )


你可能感兴趣的:(多表关联实现左连接)