Can I do a math operation inside a createCriteria

只谈情不闲聊 提交于 2019-12-12 03:53:40

问题


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

回答1:


One option would be to define a formula field in your domain class. Something like:

class SumFormula {
    Integer column1
    Integer column2
    Integer sum

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

Then, you can apply criteria as follows:

SumFormula.createCriteria().list() {
    ne("sum", 100)
}


来源:https://stackoverflow.com/questions/15254483/can-i-do-a-math-operation-inside-a-createcriteria

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!