grails gorm中的sum情况
我需要构建一个gorm查询,在 像这样grails gorm中的sum情况,grails,groovy,gorm,Grails,Groovy,Gorm,我需要构建一个gorm查询,在 像这样sum(状态为0时为1,否则为0结束)等待数据 我的gorm查询是: return Product.createCriteria().list() { resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP) projections { count("id") property("so
sum(状态为0时为1,否则为0结束)等待数据
我的gorm查询是:
return Product.createCriteria().list() {
resultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP)
projections {
count("id")
property("so.id", "id")
property("so.soNumber", "soNumber")
property("so.dateCreated", "dateCreated")
property("acc.name", "account_name")
property("proj.name", "project_name")
property("gtin", "gtin")
property("status", "status")
property("statusDate", "status_date")
sqlRestriction ("sum(case when status = 0 then 1 else 0 end) waiting_data")
groupProperty("so.id")
groupProperty("so.soNumber")
groupProperty("so.dateCreated")
groupProperty("acc.name")
groupProperty("proj.name")
groupProperty("proj.name")
groupProperty("gtin")
groupProperty("status")
groupProperty("statusDate")
}
grails gorm投影中是否可能使用sum(当…)
如何做到这一点?您肯定可以在Product.executeQuery(“…任意HQL…”)中使用它,但我不知道在投影中是否允许使用它。直接查询是否适合您可能取决于您的特定用例。是吗?假设你在问,这对你不起作用?有什么错误?@cfrick我尝试了“sqlRestriction(“sum(状态为0的情况下为1,否则为0结束)等待_数据”),但这不起作用。是否允许使用hql?