求求你不要问我为什么使用 SQL Server 6.5
SQL Server 6.5 中没有 SELECT TOP 命令,你猜怎么着,我需要它:)
我需要执行类似的操作
Select top 1 * from persons
where name ='Mike'
order by id desc
我尝试过使用 SET ROWCOUNT 1,但在这种情况下你不能使用 order by。
我最终得到
Select top 1 * from persons
where id = (select max(id) from persons where name ='Mike' )
一定有更好的方法!
有什么建议吗?
谢谢!
最佳答案
尝试选择一个临时表,按 ID 排序,然后 SET ROWCOUNT 1 并从临时表中选择 *。 (这应该适用于具有 SET ROWCOUNT N 的任何前 N 个,而您现有的解决方案仅适用于前 1 个。)
关于sql - 在 SQL Server 6.5 中选择 TOP 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3718043/