java - mybatis中如何写mysql的union all 查询?
PHP中文网
PHP中文网 2017-04-18 10:32:02
0
2
919

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讲师

répondre à tous(2)
PHPzhong

sélectionnez order_id, uid, montant, pay_type, pay_time time, '2016' comme y, '支付' comme order_type à partir de fl_pay_order où uid = 1001639998 et status = 1
UNION ALL
sélectionnez order_id, uid, amount , null comme pay_type, pay_time time, '2017' comme y, '提现' comme order_type de fl_withdraw_order où uid=1001639998 et 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>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!