java - mybatis中如何写mysql的union all 查询?
PHP中文网
PHP中文网 2017-04-18 10:32:02
[Java讨论组]

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
PHP中文网
PHP中文网

认证高级PHP讲师

全部回复(2)
PHPz

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>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号