--假设ID是自增列 SELECT TOP 10 * FROM TB ORDER BY ID DESC
有排序字段直接 select top 10 * from tb order by 排序字段 desc没有的话 需要自己去加个排序字段
select top 10 * from tb order by id desc
UP...select identity(int,1,1) myid,* into #t select top 10 * from #t order by myid desc
;with t as ( select rn=row_number()over(order by getdate()),--没ID的情况 from tb ) select * from tb order by rn desc
;with t as ( select rn=row_number()over(order by getdate()),--没ID的情况 from tb ) select top 10 * from tb order by rn desc
--1、假设ID是自增列 SELECT TOP 10 * FROM TB ORDER BY ID DESC--2、数据库中记录顺序无规律 declare @total_num int select @total_num=count(*) from tb select top 10 * from tb where [primary_key] not in (select top (@total_num-10) [primary_key] from tb)
SELECT TOP 10 *
FROM TB
ORDER BY ID DESC
select top 10 * from tb order by 排序字段 desc没有的话 需要自己去加个排序字段
UP...select identity(int,1,1) myid,* into #t
select top 10 * from #t order by myid desc
(
select rn=row_number()over(order by getdate()),--没ID的情况
from tb
)
select * from tb order by rn desc
(
select rn=row_number()over(order by getdate()),--没ID的情况
from tb
)
select top 10 * from tb order by rn desc
SELECT TOP 10 *
FROM TB
ORDER BY ID DESC--2、数据库中记录顺序无规律
declare @total_num int
select @total_num=count(*) from tb
select top 10 * from tb where [primary_key] not in (select top (@total_num-10) [primary_key] from tb)