Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEP 56:分组动态查询条件优化 #56

Closed
troyzhxu opened this issue Jun 24, 2022 · 1 comment
Closed

BEP 56:分组动态查询条件优化 #56

troyzhxu opened this issue Jun 24, 2022 · 1 comment
Labels

Comments

@troyzhxu
Copy link
Owner

troyzhxu commented Jun 24, 2022

实体类:

@SearchBean(tables = "student_course sc", groupBy = "sc.course_id", autoMapTo = "sc")
public class ScoreSum {

    private long courseId;

    @DbField("sum(sc.score)")
    private long totalScore;

}

检索时

分组字段加条件,条件放到 where 子句中:

beanSearcher.searchList(ScoreSum.class, MapUtils.builder()
        .field(ScoreSum::getCourseId, 10)
        .build());

需要执行的 SQL 是:

select sc.course_id c_1, sum(sc.score) c_2 from student_course sc where sc.course_id = 10 group by sc.course_id

聚合字段加条件,条件放到 having 子句中:

beanSearcher.searchList(ScoreSum.class, MapUtils.builder()
        .field(ScoreSum::getTotalScore, 500)
        .build());

需要执行的 SQL 是:

select sc.course_id c_1, sum(sc.score) c_2 from student_course sc group by sc.course_id having c_2 = 500
@troyzhxu troyzhxu changed the title BEP 56 分组动态查询条件优化 BEP 56:分组动态查询条件优化 Jun 24, 2022
@troyzhxu
Copy link
Owner Author

troyzhxu commented Jul 3, 2022

已在 v3.8.0 中实现:https://github.com/ejlchina/bean-searcher/releases/tag/v3.8.0

@troyzhxu troyzhxu closed this as completed Jul 3, 2022
@troyzhxu troyzhxu removed the testing 测试中 label Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant