简体   繁体   English

在grails / groovy中使用别名,条件逻辑作为条件和嵌套条件

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

I am using the criteria api in my grails app like this 我像这样在我的grails应用程序中使用标准API

 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? 如何将别名用作sum('actioncount')..命名为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? 我有一种情况,当未选择资源时...基本上,如果selected_option为'all'则不应该应用条件,我该如何在条件中创建条件逻辑? 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. 这里的目标是,我每周的每一天都有7个汇总表,运行上面的查询将为我提供日期范围内所有位置的所有操作计数。 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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