易截截图软件、单文件、免安装、纯绿色、仅160KB

帮心优化一下sql - MS-SQL Server / 基础类

declare @sql=N'SELECT TOP '+cast(@pageSize as varchar(50))+' * from (SELECT TOP '
+cast(@pageSize*@currentpage as varchar(50))+' * from [InMail] A ORDER BY A.id DESC) B ORDER BY B.id ASC'
set @sql='SELECT from ('+@sql+') C ORDER BY C.id DESC'

先是分面。但是后面又出来了排序不正确了。


1
2
3
4
5
6
7
8
9

下面是最新的。要显是在最上面
如果pageSize=2 currentPage=2
则要求取出
7
6
----------
pageSize=2 currentPage=3
5
4


不好意思,标题打错了。


引用
SQL code
--> 生成测试数据表: [InMail]
IF OBJECT_ID('[InMail]') IS NOT NULL
DROP TABLE [InMail]
GO
CREATE TABLE [InMail] ([ID] [int])
INSERT INTO [InMail]
SELECT '1' UNION ALL
SELECT '2' UNION ALL……

有没有可以优化一下的?

我靠,下面的什么贴子哦。把我问题都给盖下去了。

引用
我靠,下面的什么贴子哦。把我问题都给盖下去了。


你是什么版本的数据库?

引用
引用 4 楼 jinfengyiye 的回复:
我靠,下面的什么贴子哦。把我问题都给盖下去了。


你是什么版本的数据库?

这个不是,我是说csdn里的贴子,那些XX贴,把我的贴子盖下去了。

SQL code



Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighl


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......

sql语句问题 - Java / Web 开发

select o_customer,o_price from orders having o_price >=avg(o_price)
select o_customer,o_price from orders where o_price >=(select avg(o_price) from orders)
我感觉没有区别啊,怎么在mysql会有 ......

C# SQL 的UPDATETEXT 问题 - .NET技术 / C#

A表 有两个字段 
  id 唯一数字域
  InfoTxt text 类型
 我现在要把 id 不是14 的所有 InfoTxt字段 文本后面 都加上 'aaa' 
按下面执行下来 只有表最后一行加上了 'aaa' ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号