也就是和图片上一样的效果。要查询出数据,然后还要分页。
create table UserInfo
(
userId VARCHAR(20) primary key NOT NULL, --用户身份证号
userEmail VARCHAR(50) NOT NULL, --用户邮箱 用于登录
userPwd VARCHAR(20) NOT NULL, --用户密码
registerTime DATETIME NOT NULL, --注册时间 注册时默认当前系统时间
)
go
--用户详细信息表
create table UserDetailInfo
(
userId VARCHAR(20) NOT NULL, --用户身份证号 外键,关联用户信息表中主键userId
userName VARCHAR(50) NOT NULL, --姓名
userPhone VARCHAR(20) NOT NULL, --联系电话
userAddress VARCHAR(100) NOT NULL, --联系地址
)
--多表查询分页
select top 3* from (select userEmail,userPwd,registerTime,userName,userPhone,userAddress,ROW_NUMBER()
OVER(order by userEmail) as RowNo from UserInfo a inner join UserDetailInfo b on a.userId=b.userId)as t1
where RowNo not in(select top 0 RowNo from (select userEmail,userPwd,registerTime,userName,userPhone,userAddress,ROW_NUMBER()
OVER(order by userEmail) as RowNo from UserInfo a inner join UserDetailInfo b on a.userId=b.userId)as t2 order by RowNo asc)
我用这条语句只能显示其余6个字段,userId查询不出来。
select top 3* from (select UserInfo.userId,userEmail,userPwd,registerTime,userName,userPhone,userAddress,ROW_NUMBER()
OVER(order by userEmail) as RowNo from UserInfo a inner join UserDetailInfo b on a.userId=b.userId)as t1
where RowNo not in(select top 0 RowNo from (select userEmail,userPwd,registerTime,userName,userPhone,userAddress,ROW_NUMBER()
OVER(order by userEmail) as RowNo from UserInfo a inner join UserDetailInfo b on a.userId=b.userId)as t2 order by RowNo asc)
如果在中间加入userId的话,就会报“无法绑定由多个部分组成的标识符UserInfo.userId”