最小/最大两个变量Hibernate SQL

时间:2022-09-05 22:51:53

How can i select the minimum of two variables in hsql query language?

如何在hsql查询语言中选择最少的两个变量?

I need something like "select ... as x ... as y.... where min(x,y) <= value"

我需要像“选择...作为x ...作为y ....其中min(x,y)<= value”

The min() and max() functions apply only to column values.

min()和max()函数仅适用于列值。

Thanks in advance.

提前致谢。

2 个解决方案

#1


2  

You probably mean the LEAST value:

你可能意味着最低价值:

SELECT LEAST(x , y) FROM MYTABLE
SELECT X, Y FROM MYTABLE WHERE LEAST(X,Y) <= value 
SELECT X, Y FROM MYTABLE WHERE X <= value OR Y <= value /* this is more efficient */

You can select the minimum value among the LEAST values of the two variables in a row:

您可以在一行中选择两个变量的最小值中的最小值:

SELECT MIN(LEAST(x , y)) FROM MYTABLE

#2


1  

Sometime we simply ignore the simple ways to do things and make them complicated.

有时我们会忽略简单的做事方式并使它们变得复杂。

Looking at your query it seems you are filtering the rows whose two columns values are less than some variable.

查看您的查询,您似乎正在过滤两列值小于某个变量的行。

You may use query like this:

你可以使用这样的查询:

SELECT... AS x ... AS y.... WHERE x <= value AND y <= value 

#1


2  

You probably mean the LEAST value:

你可能意味着最低价值:

SELECT LEAST(x , y) FROM MYTABLE
SELECT X, Y FROM MYTABLE WHERE LEAST(X,Y) <= value 
SELECT X, Y FROM MYTABLE WHERE X <= value OR Y <= value /* this is more efficient */

You can select the minimum value among the LEAST values of the two variables in a row:

您可以在一行中选择两个变量的最小值中的最小值:

SELECT MIN(LEAST(x , y)) FROM MYTABLE

#2


1  

Sometime we simply ignore the simple ways to do things and make them complicated.

有时我们会忽略简单的做事方式并使它们变得复杂。

Looking at your query it seems you are filtering the rows whose two columns values are less than some variable.

查看您的查询,您似乎正在过滤两列值小于某个变量的行。

You may use query like this:

你可以使用这样的查询:

SELECT... AS x ... AS y.... WHERE x <= value AND y <= value