I've been looking for a good equivalent to the Oracle LEAST function.
我一直在寻找一个与Oracle最小功能相当的东西。
I'm hoping to implement a user defined function that does about 10 fairly complex calculations, and takes the minimum value from each of those calculations.
我希望实现一个用户定义的函数,它执行大约10个相当复杂的计算,并从每个计算中取最小值。
What I would do in Oracle is:
我在Oracle中会做的是:
SELECT LEAST
(
select expression1 from dual,
select expression2 from dual,
select expression3 from dual
) from dual
See http://www.techonthenet.com/oracle/functions/least.php for more on Oracle LEAST.
有关Oracle的更多信息,请参见http://www.techonthenet.com/oracle/functions/least.php。
If expression1 returned 10, expression2 return 5, and expression3 reeturned 30, the whole expression would return 5.
如果表情返回10,表情返回5,表情返回30,整个表情将返回5。
Because this may be about 10-20 calculations, the CASE WHEN syntax is going to get unwieldy fast.
因为这可能需要10-20次计算,所以语法会很快变得难以处理。
Although the code will be more readable if we break it up more, I thought it would be more efficient to do it within one database query. Let me know I'm incorrect on that point, please!
虽然如果我们把代码分解得更多一些,代码会更容易阅读,但是我认为在一个数据库查询中做它会更有效率。请让我知道在那一点上我错了!
I.e., is a stored procedure with 20 simple queries significantly slower than a stored procedure with one query that references a lot of tables all in one query.
即。,是一个包含20个简单查询的存储过程,比一个包含一个查询的存储过程慢得多,该查询在一个查询中引用了许多表。
2 个解决方案
#1
5
mayby this query could help:
mayby这个查询可以帮助:
SELECT min(c1)
from (
select expression1 as c1
union all
select expression2 as c1
union all
select expression3 as c1
)
#2
-1
The function Least() is applied horizontally in Oracle (on a row level), while Min() is applied vertically over a column. The example in the question required Min().
函数Least()在Oracle中水平应用(在行级别上),而Min()在列上垂直应用。问题中的示例需要Min()。
#1
5
mayby this query could help:
mayby这个查询可以帮助:
SELECT min(c1)
from (
select expression1 as c1
union all
select expression2 as c1
union all
select expression3 as c1
)
#2
-1
The function Least() is applied horizontally in Oracle (on a row level), while Min() is applied vertically over a column. The example in the question required Min().
函数Least()在Oracle中水平应用(在行级别上),而Min()在列上垂直应用。问题中的示例需要Min()。