简体   繁体   中英

using alias, condtional logic for criteria and nested criteria in grails/groovy

I am using the criteria api in my grails app like this

 def SummTblList  = ['TxnSummMon','TxnSummTue','TxnSummWed','TxnSummThu','TxnSummFri','TxnSummSat','TxnSummSun']
def res_row;

 SummTblList.each{
         res_row=it.createCriteria().list() {   

            eq('resource',resourceInstance)
            between('date', new Date()-31, new Date())        

            projections {  
            sum('actioncount')
            groupProperty 'location'         
                }                  
            }      

How do I use an Alias for sum('actioncount').. want to name it t_count?

I have a case when resource is not selected ...basically that criteria should not be applied if selected_option is 'all' how do I create a conditional logic in criteria? or do I need to create to seperate criterias totally?

The goal here is thatI have 7 summary tables one for each day of the week and running the above query will give me all action counts for all locations in a date range. now I want to sum all the counts for all seven days of the week by location. so I should finally have a total of all action counts for all location for all days of the week, how do I create a criteria which returns this?

根据此页面 ,您应该能够执行以下操作:

 sum 'actioncount', 't_count'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM