我可以在createCriteria中进行数学运算吗? [英] Can I do a math operation inside a createCriteria

查看:119
本文介绍了我可以在createCriteria中进行数学运算吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:



如果在我的表我有两列,如果两个在一起做100我不想显示它在我的结果查询





如果另一列在其他表中?



 第1栏第2列

50 50
20 20

我想要第二行

  table 1 table 2 

50 50
20 20


解决方案

一个选项是在你的域类中定义一个公式字段。类似于:

$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b static mapping = {
总和公式:'column1 + column2'
}
}

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

  SumFormula.createCriteria()。 ()


$

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

解决方案

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)
}

这篇关于我可以在createCriteria中进行数学运算吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆