问题描述
我现在t_pagetest这张表有20000条记录,其中id是从1~20000,我写的二分查找法分页存储过程.我按id倒序进行反向检索时怎么样让查询的结果倒过来.--我其实就是要Id倒序,查第1999页SELECTTOP10*FROMt_pagetestWHEREid>(SELECTMAX(id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)ASTMP)11FirstName_XXXFirstName_YYY12FirstName_XXXFirstName_YYY13FirstName_XXXFirstName_YYY14FirstName_XXXFirstName_YYY15FirstName_XXXFirstName_YYY16FirstName_XXXFirstName_YYY17FirstName_XXXFirstName_YYY18FirstName_XXXFirstName_YYY19FirstName_XXXFirstName_YYY20FirstName_XXXFirstName_YYY现在查出来是这样的,如何把它反过来20191817...11
解决方案
解决方案二:
后面orderbyid
解决方案三:
select*from(SELECTTOP10*FROMt_pagetestWHEREid>(SELECTMAX(id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)ASTMP))orderbyiddesc
解决方案四:
语句最后加上orderbyiddesc
解决方案五:
SELECTTOP10*FROMt_pagetestWHEREid>(SELECTMAX(id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)ASTMP)orderbyid
解决方案六:
引用2楼youbl的回复:
SQLcodeselect*from(SELECTTOP10*FROMt_pagetestWHEREid>(SELECTMAX(id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)ASTMP))orderbyiddesc
解决方案七:
实际上也很简单
解决方案八:
我是按"youbl"的这种做的但不行,它会变成200001999919998....19991
解决方案九:
你们不信的话你们可以自已弄张表试一下吧...
解决方案十:
to"fengling7885"这种做法也是不行的,这应该说是蛮简的,但就是不可以,我有点想不通
解决方案十一:
测试通过的代码,要加上几个别名:select*from(SELECTTOP10*FROMt_pagetestWHEREid>(SELECTMAX(a1.id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)a1))a2orderbya2.iddesc
解决方案十二:
用楼主自己的方法,外面再包一层不就行了
解决方案十三:
youbl我把你的代码COPY执行了一次,变成这样,还是不行,难道是rp问题........20000FirstName_XXXFirstName_YYY19999FirstName_XXXFirstName_YYY19998FirstName_XXXFirstName_YYY19997FirstName_XXXFirstName_YYY19996FirstName_XXXFirstName_YYY19995FirstName_XXXFirstName_YYY19994FirstName_XXXFirstName_YYY19993FirstName_XXXFirstName_YYY19992FirstName_XXXFirstName_YYY19991FirstName_XXXFirstName_YYY
解决方案十四:
我是在外面包了一层,再倒序就是不行,我郁....
解决方案十五:
呵呵,估计就是人品问题,把测试表也列出来:CREATETABLE[t_pagetest]([id][int]IDENTITY(1,1)NOTNULL,[r][char](10))GOinsertinto[t_pagetest](r)values('a')....插入100条GOselect*from(SELECTTOP10*FROMt_pagetesta3WHEREa3.id>(SELECTMAX(a1.id)FROM(SELECTTOP10idFROMt_pagetestorderbyidASC)a1))a2orderbya2.iddesc
解决方案:
orderbyiddesc
解决方案:
不行,查出来还是老样子,还是谢谢大家了,我自已再去研究了....