如何将 ms-access last() 函数转换为 sql server 2008 等效查询?代码是
SELECT
DISTINCT Last([Title].[Number) AS Row_ID
FROM [Title]
HAVING (Last([Title].[Number]) Is Null)
如何将 ms-access last() 函数转换为 sql server 2008 等效查询?代码是
SELECT
DISTINCT Last([Title].[Number) AS Row_ID
FROM [Title]
HAVING (Last([Title].[Number]) Is Null)
它没有直接的等价物,但通常可以通过 and 的组合来实现ORDER BY
,ROW_NUMBER()
或者可能MAX
- 如果您提供更多上下文和示例数据,则更容易给出明确的答案
试试这个
Select Top 1 Number From
(
Select Number From Title ORDER BY Number DESC
)
您需要使用子查询,ORDER BY
因为 sql-server 不保证没有此子句的行的顺序。请参阅示例。
declare @tbl table(f1 int, f2 varchar(10), d datetime)
insert into @tbl values (1,'1-first','20120917')
insert into @tbl values (1,'1-middle','20120918')
insert into @tbl values (1,'1-last','20120919')
insert into @tbl values (2,'2-just one','20120917')
select f1, (select TOP 1 f2 from @tbl t2 where t2.f1=t1.f1 order by d DESC) Last_f2
from @tbl t1
group by f1