SQL Server等同于Oracle LEAST? [英] SQL Server equivalent to Oracle LEAST?

查看:75
本文介绍了SQL Server等同于Oracle LEAST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找与Oracle LEAST功能相当的产品.

I've been looking for a good equivalent to the Oracle LEAST function.

我希望实现一个用户定义的函数,该函数可以执行大约10个相当复杂的计算,并从每个计算中取最小值.

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.

我将在Oracle中做的是:

What I would do in Oracle is:

SELECT LEAST
(
select expression1 from dual,
select expression2 from dual,
select expression3 from dual
) from dual

请参见 http://www.techonthenet.com/oracle/functions/least. php 有关Oracle LEAST的更多信息.

See http://www.techonthenet.com/oracle/functions/least.php for more on Oracle LEAST.

如果expression1返回10,expression2返回5,expression3重新返回30,则整个表达式将返回5.

If expression1 returned 10, expression2 return 5, and expression3 reeturned 30, the whole expression would return 5.

因为这可能需要10到20次计算,所以CASE WHEN语法很快就会变得笨拙.

Because this may be about 10-20 calculations, the CASE WHEN syntax is going to get unwieldy fast.

尽管如果我们对代码进行更多的分解,代码将更具可读性,但我认为在一个数据库查询中执行代码会更有效.让我知道我在这一点上是不正确的!

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!

即,具有20个简单查询的存储过程比具有一个查询的存储过程慢得多,该存储过程只有一个查询在一个查询中引用很多表.

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.

推荐答案

此查询可能有助于:

 SELECT  min(c1)  
 from ( 
      select expression1 as c1  
      union all
      select expression2 as c1 
      union all 
      select expression3 as c1
 )

这篇关于SQL Server等同于Oracle LEAST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆