请教关于SQL语句分页的问题 以下是查询第二页的数据:
select distinct Top 10 a.id,a.DonforUserGsm,a.Name,a.DonforUserZycp,a.DonforUserDh,a.DonforUserYhjf,a.DonforUserSzs,a.DonforUserDjs,a.DonforUserVip,a.DonforUserQq,a.DonforUserVip,a.DonforUserYhjf,a.DonforUserJcSj from [user] a,Donfor_Xxfbb_Lb b,Donfor_Xxfbb_Lb c Where CharIndex(b.Lbmc,a.DonforUserZycp)>0 and b.Ssid=c.id and c.id=18 and (a.id Not in (Select Top 20 a.id From [user] a,Donfor_Xxfbb_Lb b,Donfor_Xxfbb_Lb c Where CharIndex(b.Lbmc,a.DonforUserZycp)>0 and b.Ssid=c.id and c.id=18 Order By a.DonforUserVip Desc,a.DonforUserYhjf Desc,a.DonforUserJcSj Desc)) Order By a.DonforUserVip Desc,a.DonforUserYhjf Desc,a.DonforUserJcSj Desc
以下是查询第三页的数据:
select distinct Top 10 a.id,a.DonforUserGsm,a.Name,a.DonforUserZycp,a.DonforUserDh,a.DonforUserYhjf,a.DonforUserSzs,a.DonforUserDjs,a.DonforUserVip,a.DonforUserQq,a.DonforUserVip,a.DonforUserYhjf,a.DonforUserJcSj from [user] a,Donfor_Xxfbb_Lb b,Donfor_Xxfbb_Lb c Where CharIndex(b.Lbmc,a.DonforUserZycp)>0 and b.Ssid=c.id and c.id=18 and (a.id Not in (Select Top 30 a.id From [user] a,Donfor_Xxfbb_Lb b,Donfor_Xxfbb_Lb c Where CharIndex(b.Lbmc,a.DonforUserZycp)>0 and b.Ssid=c.id and c.id=18 Order By a.DonforUserVip Desc,a.DonforUserYhjf Desc,a.DonforUserJcSj Desc)) Order By a.DonforUserVip Desc,a.DonforUserYhjf Desc,a.DonforUserJcSj Desc
每页显示10条
现在按上面的操作第二页会重复第一页的数据,第三页会重复第二页的数据······
我知道是中间“a.id not in”后面的查询语句没加“distinct”,但是加上这个又出现ORDER BY 后台的数据必须要在查询语句,如果查询语句加上这些参数,a.id又无法比较,头痛啊