【发布时间】:2020-08-24 04:48:15
【问题描述】:
选择
(select count(*) from table2 where table2.table2Seq = table1.table1Seq) as count1,
(select count(*) from table2 where table2.table2Seq = table1.table1Seq and table2Yn = true) as count2,
(select count(*) from table2 where table2.table2Seq = table1.table1Seq) / (select count(*) from table2 where table2.table2Seq = table1.table1Seq and table2Yn = true) as count3
来自
table1
按顺序
count3
**我想要这个查询。你如何把它变成一个queryDSL?我想对子查询中的计数器除以子查询中的计数器进行排序。 **
NumberPath<Long> count1 = Expressions.numberPath(Long.class, “count1”);
NumberPath<Long> count2 = Expressions.numberPath(Long.class, “count2”);
NumberPath<Long> count3 = Expressions.numberPath(Long.class, “count3”);
JPQLQuery<OnlineTrainingCourseDto> query = getQuerydsl().createQuery()
.select(
new Dto(
ExpressionUtils.as(
JPAExpressions.select(table2.table2Seq.count())
.from(table2)
.where(table2.table2Seq.eq(table1.table1Seq)),
count1
),
ExpressionUtils.as(
JPAExpressions.select(table2.table2Seq.count())
.from(table2)
.where(table2.table2Seq.eq(table1.table1Seq)
.and(table2.table2Yn.eq(true))),
count2
),
***????? count1 / count2 as count3 ?????***
)
)
)
.from(table1)
【问题讨论】:
标签: querydsl