0

Example of Table :

Table name : Ex1

Number
2
5
6
7
1
5
10

How to find the minimum value by using ALL or ANY in SQL ?

4

3 回答 3

1

我相信你必须重写你的问题来描述你的答案,如果可能的话,你想在哪个数据库中这样做。

我不知道您为什么要这样做而不是使用 MIN 函数。

在甲骨文你可以做到这一点

select * from ex1 where number <= ANY (select number from ex1 where rownum=1 order by number asc)

但这将产生与以下相同的结果:

 select * from ex1 where rownum=1 order by number asc

你也可以这样做:

select * from ex1 where number <= ALL (select number from ex1)

您可以在此处找到更多信息。

于 2012-03-16T18:19:32.560 回答
0

冒着使用 ANY 扰乱我的 SQL Server 实例的风险(ALL 会更好),

select number 
from ex1 
where number not in 
    (select number from ex1 where number > any (select number from ex1))

我现在觉得很脏。

于 2012-03-16T18:25:01.437 回答
0

使用ALL

SELECT * 
  FROM Ex1 
 WHERE Number <= ALL ( SELECT Number FROM Ex1 AS T2 );

使用ANY

SELECT * 
  FROM Ex1 
 WHERE NOT Number > ANY ( SELECT Number FROM Ex1 AS T2 );
于 2012-03-19T12:12:24.807 回答