日期:2014-05-17  浏览次数:20515 次

我的查询语句是这样的,但是分页应该怎么写呢
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_NUMBER
select * from 
(
select Row_Number() over (order by id) as row, * from table 
) as tmp
where row between page_no1 and page_no2 --你需要分页的页码区间

--思路2 使用TOP

select top 10 * from table where
id > 
(
select max(id) from 
(select top 20 id from table order by id) as tmpTab
)
order by id
--取id在21到30之间的记录

------解决方案--------------------
表机构发一把,必须用join on ?