mybatis中如何写mysql的union all 查询?

mybatis如何写下边的sql?

select order_union.* from 
(select order_id, uid, amount, pay_type, pay_time time,'2016' ,'支付' as order_type from fl_pay_order where uid=1001639998 and status=1
UNION ALL 
select order_id, uid ,amount , null as pay_type, pay_time time ,'2017','提现' as order_type from fl_withdraw_order where uid=1001639998 and status=3)
as order_union
order by order_union.time desc limit 0,10
阅读 17.5k
2 个回答

select order_id, uid, amount, pay_type, pay_time time,'2016' as y,'支付' as order_type from fl_pay_order where uid=1001639998 and status=1
UNION ALL
select order_id, uid ,amount , null as pay_type, pay_time time ,'2017' as y,'提现' as order_type from fl_withdraw_order where uid=1001639998 and status=3

<select id="yourId" parameterType="com.yourcomparny.yourmodel.YourType" resultMap="yourResultMap">
        SELECT ORDER_UNION.*
              FROM (SELECT ORDER_ID,
                           UID,
                           AMOUNT,
                           PAY_TYPE,
                           PAY_TIME TIME,
                           '2016',
                           '支付' AS ORDER_TYPE
                      FROM FL_PAY_ORDER
                     WHERE UID = 1001639998
                       AND STATUS = 1
                    UNION ALL
                    SELECT ORDER_ID,
                           UID,
                           AMOUNT,
                           NULL AS PAY_TYPE,
                           PAY_TIME TIME,
                           '2017',
                           '提现' AS ORDER_TYPE
                      FROM FL_WITHDRAW_ORDER
                     WHERE UID = 1001639998
                       AND STATUS = 3) AS ORDER_UNION
             ORDER BY ORDER_UNION.TIME DESC LIMIT 0, 10
    </select>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏