求一条SQL语句 - MS-SQL Server / 基础类
表名news 字段ID,TITLENAME
字段ID值为 1, 4, 6, 7, 8
现在我要求一条SQL语句得到前三行语句的第三行记录 也就是ID是6的语句.select top 1 * from news order by id desc 还有TOP 3(前三行) 如何录入 ;毕竟我遇到的问题是ID是不知道的参数;并且只取一行记录;
SQL code:
declare @n int
set @n=3
select top 1 * from(select top (@n) * from news order by id) a
SQL code:
declare @n int
set @n=3
print('select top 1 * from(select top '+ltrim(@n)+' * from news order by id) a')
SQL code:
--2000
declare @n int
set @n=3
print('select top 1 * from(select top '+ltrim(@n)+' * from news order by id) a order by id desc')
--2005
declare @n int
set @n=3
select top 1 * from(select top (@n) * from news order by id) a order by id desc
SQL code:
create proc Id_proc
declare @id int
as
begin
select top 1 * from news where ID not in (select top (@n-1) ID from news)
end
--应用:
exec Id_proc 3
SQL code
Code highlighting produced by Actipro CodeHighlighter (fr
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP
参考:http://hi.baidu.com/toiota ......
id url rank ......