首页 新闻 会员 周边 捐助

关于子查询分页sql

0
悬赏园豆:10 [已解决问题] 解决于 2013-05-22 23:40

我想对一个三表连接后的结果进行分页查询,可是怎么写也不对,大家看看!

SELECT TOP 2 *
FROM (select B.Id,B.Name,B.SmallImageUrl,B.Description,B.CreateTime,C.UserId,C.UserName,C.PhotoUrl from BookFavorites as A
inner join BookInfo as B on A.BookId=B.Id
inner join [User] as C on A.UserId=C.UserId
where A.typeid=0 and A.UserId=17)
WHERE Id NOT IN
(
SELECT TOP 2 Id FROM (select B.Id,B.Name,B.SmallImageUrl,B.Description,B.CreateTime,C.UserId,C.UserName,C.PhotoUrl from BookFavorites as A
inner join BookInfo as B on A.BookId=B.Id
inner join [User] as C on A.UserId=C.UserId
where A.typeid=0 and A.UserId=17)
)
ORDER BY Id;

sql
菩提下的木树的主页 菩提下的木树 | 初学一级 | 园豆:84
提问于:2013-03-18 22:42
< >
分享
最佳答案
0

你具体的 要的结果是什么?

收获园豆:5
走zai 路上 | 菜鸟二级 |园豆:214 | 2013-03-18 22:54

就是我想要对(select B.Id,B.Name,B.SmallImageUrl,B.Description,B.CreateTime,C.UserId,C.UserName,C.PhotoUrl from BookFavorites as A
inner join BookInfo as B on A.BookId=B.Id 
inner join [User] as C on A.UserId=C.UserId
where A.typeid=0 and A.UserId=17)里面查到的数据进行分页

菩提下的木树 | 园豆:84 (初学一级) | 2013-03-18 22:58
其他回答(1)
0

你的分页排序依据是什么?b.id?

伪代码为:

sqlstr="select top pagesize xxx from xxx";

if( page=1 ) sqlstr+="order by id";

else sqlstr+="where id>(select max(id) from (select top pagesize*(page-1) id from xxx order by id) a) order by id

收获园豆:5
飞来飞去 | 园豆:2057 (老鸟四级) | 2013-03-18 23:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册