TABLE:1 asdf
2 斯蒂芬
3 地地道道
4 ggg
求查出 3 地地道道
4 ggg
就是差最后N条记录,要顺序的不要倒序。。谢谢
2 斯蒂芬
3 地地道道
4 ggg
求查出 3 地地道道
4 ggg
就是差最后N条记录,要顺序的不要倒序。。谢谢
解决方案 »
- 行列转换
- 请问:sql 2000和 sql 2005 可以同时安装在一台机器么? 如果可以,那么先安装哪个? 还有别的要注意的事项么?
- 数据库触发器怎么样自动计算日期并在另一个表中按周次添加记录
- eclipse连接SQL2008时出错
- 字段的值怎么让它自动递增?但格式是00001第二行为00002不用人干涉??谁能告诉下??
- SQL并发问题
- 在WIN98和NT(2000)中的SQL到底有什么不同?
- 为什么我的SQL2000安装不了救救我吧,重复好多次都不行了。谢谢了
- 关于字符串的并集问题?
- 请教各位大虾,关于排名的问题,急。。(在线等待)谢。同时散分。
- 中式日期与美式日期的转换
- 急,关于自动排序的问题!!
insert into @TABLE
select 1,'asdf' union all
select 2,'斯蒂芬' union all
select 3,'地地道道' union all
select 4,'ggg'declare @n smallint
set @n=2select *
from
(select top (@n) * from @TABLE order by cl1 desc)t
order by cl1cl1 cl2
----------- --------
3 地地道道
4 ggg
-->Author:happy_stone【不會飛的石頭】
-->Date :2009-10-20 07:51:15
if not object_id('Tempdb..#t') is null
drop table #t
Go
Create table #t([Col1] int,[Col2] nvarchar(4))
Insert #t
select 1,N'asdf' union all
select 2,N'斯蒂芬' union all
select 3,N'地地道道' union all
select 4,N'ggg'
Go
declare @N int
set @n=2
select * from(
select top (@n) * from #t order by col1 desc)t
order by col1 asc
/*
Col1 Col2
----------- ----
3 地地道道
4 ggg(2 個資料列受到影響)
*/
-->Author:happy_stone【不會飛的石頭】
-->Date :2009-10-20 07:51:15
if not object_id('Tempdb..#t') is null
drop table #t
Go
Create table #t([Col1] int,[Col2] nvarchar(4))
Insert #t
select 1,N'asdf' union all
select 2,N'斯蒂芬' union all
select 3,N'地地道道' union all
select 4,N'ggg'
Go
--MSSQL2000
declare @N int
set @n=2
exec('select * from(
select top '+@n+' * from #t order by col1 desc)t
order by col1 asc')
/*
Col1 Col2
----------- ----
3 地地道道
4 ggg(2 個資料列受到影響)
*/