日期:2014-05-18 浏览次数:20536 次
select user.id,user.name from user where user.id in( select userid,count(roleid) from 中间表 where count(roleid)>1 group by userid); --等大牛
------解决方案--------------------
role--有多个角色时把加条件加上b.roleName in('普通','管理员')
select * from [user] as a where not exists(select 1 from [role] as b where b.roleName in('普通','管理员') and not exists(select 1 from 中间表 where userID=a.userID and roleID=b.roleID))
------解决方案--------------------
select distinct a.name from [user] a inner join 中间表 b on a.id=b.userid inner join [role] c on c.id=b.roleid inner join [role] d on d.id=b.roleid where c.roleName='普通' and d.roleName='管理员'