gpt4 book ai didi

sql - 从 TOP 数量的记录中获取 MAX 值

转载 作者:行者123 更新时间:2023-12-03 02:03:25 25 4
gpt4 key购买 nike

我有以下 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 thekeyword '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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com