Home sum case when in grails gorm
Reply: 0

sum case when in grails gorm

user1373
1#
user1373 Published in May 23, 2018, 10:41 pm

I need build a gorm query returning a status field sum case when

like this sum(case when status = 0 then 1 else 0 end) waiting_data

my gorm query is :

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")

            }

Is possible use sum(case when ...) in grails gorm projections??

how do this?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301383 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO