查询多表集合(union)、查询时建临时字段、查询时给字段设置默认值

 1 (select recharge_arrive_time as time,recharge_amount as amount,state,'充值' AS type from onlinerecharge where user_id=1)
 2 UNION 
 3 (select confirm_time as time,withdraw_cash_amount as amount,state,'提现' AS type from withdrawcash where user_id=1)
 4 UNION 
 5 (select i.create_time as time,i.investment_amount as amount,i.invest_state as state, b.bid_name as type from invest i
 6 INNER JOIN bid b
 7 on i.bid_id=b.bid_id
 8 where i.user_id=1)
 9 UNION 
10 (select r.exact_repayment_time as time,r.should_repayment_amount as amount,r.state as state, b.bid_name as type from repayment r 
11 INNER JOIN bid b
12 on r.bid_id=b.bid_id
13 where r.user_id=1)
14 UNION 
15 (select created_date_long as time,reward_amount as amount,reward_source as state,reward_name AS type  from investreward where user_id=1)
16 UNION 
17 (select a.created_date_long as time,a.actual_amount as amount,ac.amount as state,'多利宝存入' as type from dollyadd a
18 INNER JOIN dollyflow f
19 on a.dolly_flow_id= f.dolly_flow_id
20 INNER JOIN dollyaccount ac
21 ON a.user_id = ac.user_id
22 where a.user_Id = 1)
23 UNION
24 (select r.redeeml_arrive_time as time,r.amount as amount,'' as state,'多利宝赎回' as type from dollyredeem r
25 INNER JOIN dollyflow f
26 ON r.dolly_flow_id=f.dolly_flow_id
27 where r.user_id=1)
28 UNION
29 (select u.hb_get_time as time,h.hongbao_amount as amount,h.hongbao_name as state,'红包奖励' as type from userhongbao u 
30 INNER JOIN hongbao h
31 ON u.hongbao_id= h.hongbao_id
32 where user_id=1)
33 ORDER BY time DESC

 

posted @ 2018-05-02 15:47  林夕Emma  阅读(630)  评论(0编辑  收藏  举报