如何测试两个数据库列之间是否存在值?
我需要做这样的事情:
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/