超高难度:关联的两个表的SQL分页问题。
CREATE TABLE contactGroupsend
(
contactGroupsendId int IDENTITY(1,1) primary key, --主键 自动增加
contactId int , --联系人ID
contactGroupName varchar(100), --组的名称 唯一
userLdapId Varchar(100) --登陆名,
)
CREATE TABLE Contact
(
contactId int IDENTITY(1,1) primary key, --ID主键
contactName varchar(100), --姓名
contactTel varchar(100), --手机号码
contactCompanyTel varchar(100), --公司电话
contactEmail varchar(100), --电子邮箱
contactChatNumber varchar(100), --聊天工具号码
contactMark varchar(1000), --备注
userLdapId Varchar(100) --用户名或用户ID
)
GO
---
查询Contact中的信息,条件是:
select contactId from Contact where contactId in( select contactId from contactGroupsend where userLdapId='aaa' and contactGroupName='同事')
---
请考虑一个问题,如果是下面这种做法的话.当contactId 不连续的话就不对了..
select top 8 * from Contact where userLdapId='aaa'
and contactId in( select contactId from contactGroupsend where userLdapId='aaa' and contactGroupName='同事')
and (contactId>(select max(contactId) from (select top 8 contactId from Contact where userLdapId='aaa' order by contactId) as t))
order by contactId
--
每页8条,如果( select contactId from contactGroupsend where userLdapId='aaa' and contactGroupName='同事') 查出来的contactId 是1,2,3,4,5,6,7,9
那么第一页出来的只有1,2,3,4,5,6,7 七条数据.
--
关键是这个条件不知道怎么处理:contactId in( select contactId from contactGroupsend where userLdapId='aaa' and contactGroupName='同事')
谢谢各位的关注。