我有两对的三个整数值。
我想将其用作 WHERE 子句中的 IN 列表。
我想在这样的查询中使用上面的两对列表:
SELECT
*
FROM
WEEK_REPORT A
WHERE
A.user_id IN ('test2','test5' ) AND
(A.year, A.week_no) IN ((2019,4),(2019,5),(2019,6));
为此,我编写了如下源代码:
// lastYear=2019, lastWeekNo=4
Tuple t = JPAExpressions.select(Expressions.constant(lastYear), Expressions.constant(lastWeekNo))
.from(weekReport)
.fetchOne();
// currentYear=2019, currentWeekNo=5
Tuple t2 = JPAExpressions.select(Expressions.constant(currentYear), Expressions.constant(currentWeekNo))
.from(weekReport)
.fetchOne();
// nextYear=2019, nextWeekNo=4
Tuple t3 = JPAExpressions.select(Expressions.constant(nextYear), Expressions.constant(nextWeekNo))
.from(weekReport)
.fetchOne();
return queryFactory
.select(weekReport)
.from(weekReport)
.where(weekReport.user.eq(user)
.and(Expressions.list(weekReport.year, weekReport.weekNo).in(t, t2, t3)))
.fetch();
但是,不会输出正确的结果并发生错误。
java.lang.UnsupportedOperationException: null
at com.querydsl.jpa.JPASubQuery.fetchOne(JPASubQuery.java:66) ~[querydsl-jpa-4.1.4.jar:na]
我在官方文档里查了一下,没有出来。
有办法吗?
谢谢你。
最佳答案
试试这个
SELECT
*
FROM
WEEK_REPORT A
WHERE
A.user_id IN ('test2','test5' ) AND
concat(A.year, A.week_no) IN (20194,20195,20196);