SQL从表中选择最大值

StK*_*ler 3 t-sql max

在我的采访中,我问它是如何可以选择从DB最大值没有关键字MAXTOP.

我的回答是:

select Table.Value 
from Table 
where Table.Value >= all( select Table.Value from Table) 
Run Code Online (Sandbox Code Playgroud)

但这不是正确的.面试官说我应该只选择一个.

有任何想法吗 ?

谢谢 ;)

Ale*_* K. 6

怎么样;

select -min(-fld) from table
Run Code Online (Sandbox Code Playgroud)


低效率和丑陋的 Woops错过了单一选择限制

select distinct Value from Table T
  where not exists (select Value from Table where Value > T.Value)
Run Code Online (Sandbox Code Playgroud)

  • +1好答案(假设`value`虽然是数字) (2认同)