我想对一个三表连接后的结果进行分页查询,可是怎么写也不对,大家看看!
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;
你具体的 要的结果是什么?
就是我想要对(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)里面查到的数据进行分页
你的分页排序依据是什么?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