gpt4 book ai didi

sql - 获取第二高的采样日期

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

我试图获得第二高的样本日期并得到以下错误,请告诉我我在哪里做错了

(SELECT* FROM resheader WHERE sampledate =
(SELECT MAX(sampleDate) FROM resheader
WHERE sampleDate < (SELECT MAX(sampleDate) FROM resheader)
)
) as 'Previous Sample'

错误

Msg 116, Level 16, State 1, Line 12 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

最佳答案

在 SQL Server 2012 中,您可以使用 OFFSET FETCH获取第二行的子句(按所需标准排序后):

SELECT * FROM resheader 
ORDER BY sampledate DESC
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY

关于sql - 获取第二高的采样日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31658881/

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