简体   繁体   English

Grails最小值获取

[英]Grails minimum value fetch

I am working to fetch the minimum value from a table in Grails where the vehicleid and the type is given 我正在努力从Grails的表格中获取最小值,其中给出了车辆编号和类型

there are many values associated from that vehicleid and type i need to fetch the minimum date associated with that vehicleid . 我需要获取与该车辆ID相关的许多值和类型,以获取与该车辆ID相关的最短日期。 I have tried this but it is not working for the startDate param. 我已经尝试过了,但是它不适用于startDate参数。

List vehicleDate= Table.createCriteria().list() {
   and{
      eq('vehicleid',vehicleIDGiven)
      eq('type',type)
      min("startDate")
   }
}

what could be the query like 查询可能是什么样的

If you just need to fetch the minimum value, you could use a projection as documented here . 如果仅需要获取最小值,则可以使用此处记录的投影。

Not tested, but your criteria should look something like this: 未经测试,但您的条件应如下所示:

def result = Table.createCriteria().list() {
    and{
        eq('vehicleid',vehicleIDGiven)
        eq('type',type)
    }
    projections {
        min("startDate")
   }
}

println "Minimum start date is ${result[0]}"

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

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