沈越. 2018-12-13 03:59 采纳率: 0%
浏览 1543

需要查询出所有字段,让userId显示,但是只显示一个,求大佬解答一下

图片说明

也就是和图片上一样的效果。要查询出数据,然后还要分页。

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”

  • 写回答

2条回答

  • 该好友未把您拉黑 2018-12-13 05:22
    关注

    UserInfo.userId 改成 a.userId

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作