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

mohugomohu 2012-07-24 08:27:20
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)


这是查询我想要的全部数据的,然后现在想分页怎么弄呢
...全文
98 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
喂大的程序员 2012-07-25
  • 打赏
  • 举报
回复
表机构发一把,必须用join on ?
mohugomohu 2012-07-25
  • 打赏
  • 举报
回复
这两种办法用不了,因为用的是join的语法,根本写不了
以学习为目的 2012-07-24
  • 打赏
  • 举报
回复


--思路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之间的记录

--小F-- 2012-07-24
  • 打赏
  • 举报
回复
TOP或者ROW_NUMBER()OVER分页 BAIDU一下N多。

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧