sql - Grails withCriteria,两个数据库列之间的值?

标签 sql grails criteria

如何测试两个数据库列之间是否存在值?

我需要做这样的事情:

between(column1, column2, 'value')

或类似这样的东西:
or{
   and {
         ge("hora_inicio", evento.hora_inicio)
         le("hora_fim", evento.hora_inicio)
      }
   and {
         ge("hora_inicio", evento.hora_fim)
         le("hora_fim", evento.hora_fim)
       }
  }

有什么想法吗?

谢谢!

最佳答案

没有选项可以检查两个列是否在一个值之间。您将不得不做两个单独的比较。您可以将一个数据库列与另一个数据库列进行比较,但是看起来并不需要那样。在此处查看有关此文档:http://docs.grails.org/latest/ref/Domain%20Classes/createCriteria.html

从第二个示例中,您似乎需要查找所有开始时间在evento.hora_inicio和evento.hora_fim之间或顺序时间在evento.hora_inicio和evento.hora_fim之间的条目。

感觉可以简化为查找在evento.hora_fim之前具有hora_inicio且在evento.hora_inicio之后具有hora_fim的所有条目。看起来像这样:

Event evento = getEventFromSomewhere()
Appointment.createCriteria().list{
    le 'hora_inicio', evento.hora_fim
    ge 'hora_fim', evento.hora_inicio
}

关于sql - Grails withCriteria,两个数据库列之间的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40598388/

相关文章:

macos - 使用TextMate打开Grails项目

caching - Grails Controller 在更改数据库时未刷新缓存

hibernate - 在 Hibernate 标准中使用 setFetchMode 时,如何对 oneToMany 表设置限制

休眠+标准。如何在没有一个引用实体的情况下返回结果

安卓房间 : How to Migrate Column Renaming?

mysql - 无法在 MySQL 触发器中将变量设置为 CURRENT_DATE()

sql - 使用 FIRSTVALUE()/LAST_VALUE() 进行分组

sql - 如何使用 HeidiSQL 在 Firebird 中设置超时?

Grails hasOne 关系真的是双向的吗?

java - 日期的 hibernate 条件