我有以下 MS SQL 查询
select top 10 RegisterTime
from orderNotifications
order by RegisterTime asc
如何获取该查询的最大RegisterTime
?
我已经尝试过了
select max(RegisterTime) in (
select top 10 RegisterTime
from orderNotifications
order by RegisterTime asc
)
但是我得到了
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'in'.
Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'order'.
最佳答案
使您的 TOP 10
查询成为子查询:
SELECT MAX(RegisterTime)
FROM (SELECT TOP 10 RegisterTime
FROM orderNotifications
ORDER BY RegisterTime
)sub
关于sql - 从 TOP 数量的记录中获取 MAX 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20691189/