如何计算正文长度介于 0 到 25 个字符之间的消息数量?
Message.countBy('from Message m where m.body.length <= 25')
对我来说不幸的是,
countBy
不接受字符串参数。
最佳答案
查看动态方法引用,您可能做的最好的事情是使用 executeQuery
而不是 count*
:
Message.executeQuery('select count(m) from Message m where SIZE(m.body) < 25')
编辑:这里有几个链接可能有助于编写/执行查询:
关于sql - 如何在 Grails/Hibernate : Message. countBy 中计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/466778/