在QueryDSL中使用带有“ in”运算符的两个字段

根佐托

我必须使用QueryDSL编写此查询:

select *
from table
where(field1, field2) in (
    select inner_field_1, inner_field2
    from ...
);

但是,我不知道如何在QueryDSL中将两个字段(field1和field2)与“ in”运算符一起使用。我一直在文档中寻找它,但是还没有看到两个字段的任何示例。

这是我到目前为止的内容:

Expression<?>[] projection = {
    table.field1,
    table.field2
};

SQLSubQuery outterQuery= new SQLSubQuery()
    .from(table)
    .where([some expression].in(inneryQuery.list(projection))) // ???
    .groupBy(contentcache1.programId, contentcache1.id);

任何帮助,将不胜感激

提前非常感谢你

雷米

您可以将原始查询重写为:

select *
from table, (select distinct inner_field_1, inner_field2 from ...) subquery
where field1 = subquery.field1 and field2 = subquery.field2

然后,您不必使用IN运算符。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章