39

如果我用 HQL 写

A between 5 and 10

是否相当于

A >= 5 and A <= 10

或者

A > 5 and A < 10

或其他4种组合?

4

2 回答 2

54

我在 Hibernate 文档中没有找到任何行为规范,但是betweenHQL 中的运算符被翻译为betweenSQL 中的运算符,这是包容性的。

所以between在 HQL 中也是包容的,即

A between 5 and 10

相当于

A >= 5 and A <= 10
于 2009-02-25T17:31:30.050 回答
4

显然,对此存在一些混淆。自然语言会暗示它是排他性的,但事实并非如此。实际上它的 A >= 5 和 A<=10。由于已经给出了相互矛盾的答案(并且已删除),因此需要进一步澄清:(来自http://www.techonthenet.com/sql/between.php

Example #1 - Numbers

The following is an SQL statement that uses the BETWEEN function:

SELECT *
FROM suppliers
WHERE supplier_id between 5000 AND 5010;

This would return all rows where the supplier_id is between 5000 and 5010, inclusive. It is equivalent to the following SQL statement:

SELECT *
FROM suppliers
WHERE supplier_id >= 5000
AND supplier_id <= 5010;
于 2009-02-26T07:28:57.603 回答