HQL中的两者之间是否严格比较?

2022-09-01 03:10:59

如果我用HQL写作

A between 5 and 10

是否等效于

A >= 5 and A <= 10

A > 5 and A < 10

还是4种组合中的其他一些?


答案 1

我没有在Hibernate文档中找到任何行为规范,但是HQL中的运算符被转换为SQL中的运算符,这是包容性的。betweenbetween

所以在HQL中也是包容性的,那就是between

A between 5 and 10

等效于

A >= 5 and A <= 10

答案 2

显然,对此存在一些混淆。自然语言会暗示它是排他性的,但事实并非如此。实际上,它的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;

推荐