我想运行类似于以下的 sql 查询:
SELECT count(*) from WORDS where wordId in (4,5,6)
我怎样才能在 Gorm 中写这个?我知道 grails 有countBy*,但我不能将多个值传递[4,5,6]给它。
我应该使用execute吗?
我想运行类似于以下的 sql 查询:
SELECT count(*) from WORDS where wordId in (4,5,6)
我怎样才能在 Gorm 中写这个?我知道 grails 有countBy*,但我不能将多个值传递[4,5,6]给它。
我应该使用execute吗?
您还可以rowCount在计算结果行数的预测中使用。注意id为Long
Words.createCriteria().get {
'in'('id', [4,5,6]*.toLong()) //or [4L, 5L, 6L]
projections {
rowCount()
}
}
您可以使用投影。
Words.createCriteria().get {
'in'('id', [4,5,6])
projections {
count('id')
}
}