--有ID
1.
select top (b-a) * from
(select top b * from tablename order by id) order by id desc2.
select top n * from tablename order by id desc
解决方案 »
- sql 2000 telnet 内网 1433 可以 外网不行!!!
- 可扩充散列索引的建立和语法树的问题。请帮忙!
- 两句SQL语句,用分号隔开,使用ADO的一个CMD执行,那么它有事务功能吗。
- 向邹建等高手请教:关于库存日报统计
- 高手帮我看看存储过程创建里创建全局临时表的问题
- odbc 错误
- SQL Server的连接问题(高手请进)
- sql server 7/2000 或msde 安装的最后连接不上服务器,为什么?请大虾们救救我吧!我快不行了。100分报答救命之恩。
- 急问:如何读出SqlServer中对一个字段的描述
- 如何判断数据库中1个表已经存在,这样不会重复创建一个新表(用sql语句)?
- 請教一個sql語法錯誤
- 从远程数据库导入本地报错
select top (b-a) * from --b-a要取数值
(select top b * from tablename order by id) c order by id desc2.
select top n * from tablename order by id desc
--下面在本地测试成功
1.
select top 5 * from
(select top 10 * from T_Employee order by nid) c order by nid desc2.
select top 5 * from T_Employee order by nid desc
select * from dbo.T_Employee
所有有时觉得MySql都有的东西 ,居然Sqlserver 2000没有.等待Sqlserver2005出来了要好生看看!
我觉得在BS开发上功能应该加强了很多毕竟现在BS是主流
select top b-a+1 * from table where id not in(select top b-1 id from table)
2
select top n * from tablename order by id desc
where B.id not in (select top a id from 表)
select identity(int,1,1) as rowid,* into #T from 表select * from #T where rowid between a and bselect top n * from #T order by rowid desc
妈的,就感觉效率太低了。
而且,用一个中间表还不行,不知道内部被做了什么优化public ResultSet getpageinfo(DBConnection db, String sql, int page)
throws Exception
{
ResultSet rs = null;
try{
int i = sql.toLowerCase().indexOf("select ");
if(i == -1){
throw new Exception("error sql of no select");
}
String subsql = sql.substring(i + "select".length());
sql = "select top " + (page * this.rowsperpage) + " " + subsql;
//create page info
sql = "select identity(int) as empriser_id, * into #empriser_temp1 from (" + sql + ") as temp";
sql += this.linedelim + "select * into #empriser_temp2 from #empriser_temp1 where empriser_id > " + (page - 1) * this.rowsperpage;
sql += this.linedelim + "alter table #empriser_temp2 drop column empriser_id";
sql += this.linedelim + "select * from #empriser_temp1";
sql += this.linedelim + "drop table #empriser_temp1" + this.linedelim + "drop table #empriser_temp2";
rs = db.executeQuery(sql);
}finally{ }
return rs;
}
declare @_count int,@Rowcount int
set @_count=1set @Rowcount=(select count(*) from table1)
select @Rowcountset @_count=@Rowcount-@_count-----正數的行數exec('
select top 1 User_ID from table1 where User_ID not in
(select top '+@_count+' User_ID from table1)
')
有id就没有这种问题了