yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://mybatis-plus-join.github.io
Apache License 2.0
1.18k stars 128 forks source link

怎么实现left join 子查询 #168

Closed zjfksj closed 3 months ago

zjfksj commented 3 months ago

当前使用版本(必填,否则不予处理)

3.6.3

该问题是如何引起的?(确定最新版也有问题再提!!!)

怎么实现left join 子查询 SELECT o.*, refundQuantity.quantity FROM qg_t_order as o left join (select ip.order_id, sum(case when ip.item_parent_status in (4,5,9) then 1 else 0 end) as quantity from qg_t_items_parent as ip group by ip.order_id) as refundQuantity on (o.id = refundQuantity.order_id)

重现步骤(如果有就写完整)

报错信息

zjfksj commented 3 months ago
    queryWrapper.selectAll(QgTOrder.class)
            .select("refundQuantity.quantity")
            .leftJoin("(SELECT ip.order_id, sum( CASE WHEN ip.item_parent_status IN ( 4, 5, 9 ) THEN 1 ELSE 0 END ) AS quantity FROM qg_t_items_parent AS ip GROUP BY ip.order_id ) AS refundQuantity ON (t.id = refundQuantity.order_id)")
                    .orderByDesc("refundQuantity.quantity");实现了