这里的case该如何用
userroles:
userid roleid usertype
1 1 1
select UserName=(case UserType when 1 then (select UserName from A g where g.UserID=UserID ) end)
from userroles
我想从userroles选出由不同UserType对应的表中的用户名,如上,当usertype=1时,从A表选出与当前userid对应的username,
问题是select UserName from A g where g.UserID=UserID,这里的右边的userid并不是对应的每一列的userid,似乎是全部都检索了,出现了以下错误:
“子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。”