首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

小弟我的查询语句是这样的,但是分页应该如何写呢

2012-10-10 
我的查询语句是这样的,但是分页应该怎么写呢SQL codeselect * from (Select Temperature, A.DateHappen,A.

我的查询语句是这样的,但是分页应该怎么写呢

SQL code
select * from (Select Temperature, A.DateHappen,A.BoxSN from Monitor_Temperature A inner Join (Select BoxSN,Max(DateHappen) As DateHappen from Monitor_Temperature where 1=1  Group By BoxSN) B On A.BoxSN=B.BoxSN And A.DateHappen=B.DateHappen) as LastTempearature,Basic_Box  where LastTempearature.BoxSN=Basic_Box.BoxSN  and TemperatureState=1 and (Temperature<2 or Temperature>8)


这是查询我想要的全部数据的,然后现在想分页怎么弄呢

[解决办法]
TOP或者ROW_NUMBER()OVER分页 BAIDU一下N多。
[解决办法]
SQL code
--思路1 使用ROW_NUMBERselect * from (select Row_Number() over (order by id) as row, * from table ) as tmpwhere row between page_no1 and page_no2 --你需要分页的页码区间--思路2 使用TOPselect top 10 * from table whereid > (select max(id) from (select top 20 id from table order by id) as tmpTab)order by id--取id在21到30之间的记录
[解决办法]
表机构发一把,必须用join on ?

热点排行