0

Is it posible to do a math problem inside a createCriteria?

For example:

If in my table I have two columns, if the two together make 100 I don't want to show it in my result of the query

or

if the other column is in other table?

table

column 1  column 2

  50        50
  20        20

I want the second row

or

table 1       table 2 

  50            50
  20            20
4

1 回答 1

3

一种选择是在您的域类中定义一个公式字段。就像是:

class SumFormula {
    Integer column1
    Integer column2
    Integer sum

    static mapping = {
        sum formula: 'column1 + column2'
    }
}

然后,您可以应用以下条件:

SumFormula.createCriteria().list() {
    ne("sum", 100)
}
于 2013-03-06T18:18:21.090 回答