SELECT EmployeeName, Date
ORDER BY Date desc
where Lastname = @lastname
OFFSET 1 Rows
FETCH NEXT 1 ROW ONLY;
如果我在上述查询中未包含where
,那么它完全有效,但如何在一个语句中包含ORDER BY
,WHERE
,OFFSET
和FETCH
,我想根据日期和姓氏选择第n行
答案 0 :(得分:1)
where
子句应该在order by
子句之前
此外,您缺少from
子句。
SELECT EmployeeName, Date
FROM <YourTableNameHere>
WHERE Lastname = @lastname
ORDER BY Date desc
OFFSET 1 Rows
FETCH NEXT 1 ROW ONLY;
(用您的实际表名替换<YourTableNameHere>
)