yulichang / mybatis-plus-join

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

group by 字段问题 #44

Closed kala888 closed 1 year ago

kala888 commented 1 year ago

platform和merchant是一对多关系。 做关联count+group的时候,需要格式化结果, groupBy函数不够自然或者存在bug

        MPJLambdaWrapper<Merchant> qw = new MPJLambdaWrapper<>();
        qw.selectCount(Merchant::getId, CandidateValue::getValue);
        qw.selectAs(Platform::getName, CandidateValue::getTitle);
//        qw.groupBy(CandidateValue::getTitle); // 报错 mapper not find by class <CandidateValue>
//        qw.groupBy(Platform::getName); // 报错, sql 是GROUP BY t.name,应该是title
        qw.groupBy("title"); // ok,但是不如上面的两种方式自然
        qw.leftJoin(Platform.class, Platform::getId, Merchant::getPlatform);
kala888 commented 1 year ago

用v1.4.5,qw.groupBy(Platform::getName)好了