【问题标题】:Grails withCriteria, value between two database columns?Grails withCriteria,两个数据库列之间的值?
【发布时间】:2016-11-14 21:48:51
【问题描述】:

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

我需要做这样的事情:

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

有什么想法吗?

谢谢!

【问题讨论】:

    标签: sql grails criteria


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 2011-05-09
      • 2015-08-09
      • 1970-01-01
      • 2022-11-04
      相关资源
      最近更新 更多