我正在尝试在 GORM 中执行以下 sql 语句
select * from table1 where table1.x not in
(select x from table 2 where y='something');
所以,我有两个表,需要从表 1 中找到表 2 中没有的条目。在 Grails 中
def xx= table2.findByY('something')
def c = table1.createCriteria()
def result= c.list {
not (
in('x', xx)
)
}
语法错误,我不确定如何模拟 not in sql 逻辑。
作为学习点,如果有人也能告诉我为什么 grails/groovy 中的减号 (-) 运算符不适用于列表。我尝试分别获取 x 和 y,并执行 x.minus(y),但它不会更改列表。我在 Groovy on Grails list - not working? 看到了解释,但我希望定义的列表是本地的。
非常感谢。
最佳答案
嗯,我自己也在学习 GORM,但我看到的一件事是 in 是 groovy 中的保留字,因此需要转义为 'in'
关于hibernate - Grails GORM( hibernate )查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2542646/