sql server 中取前n行字段最大值问题

例子 取前三行最大ID

select MAX(A.ID) from (select top 3 ID from Students)AS A

这样写得到的却是整个表的最大ID值,并不是我们需要的值

要在句中加入order by ID

select MAX(A.ID) from (select top 3 ID from Students order by ID  ) as A

但是 不能是 order by ID desc,降序也无法得到结果。

还知道为啥,请指点。

猜你喜欢

转载自www.cnblogs.com/ylancf/p/11008974.html