简体   繁体   中英

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

there are many values associated from that vehicleid and type i need to fetch the minimum date associated with that vehicleid . I have tried this but it is not working for the startDate param.

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]}"

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