SQL查询,用于根据其角色分隔用户 [英] SQL query for seperating user according to its role
问题描述
大家好,
我的数据库中有两个表,一个是:User_Master,另一个是User_Role
现在user_role具有
1. ZM
2. SBU
3.管理员
4.普通用户
user_master具有
Loginid用户名角色
1. XYZ 1
2. ABC 3
3. PQR 1
等..
现在我需要的是拥有用户角色明智的数据
即
ZM SBU管理员普通用户
XYZ空ABC空
PQR NULL NULL NULL
等...
请帮我怎么可能..
问候,
Krunal panchal
Hello everyone,
I have two tables in my database one is :User_Master another is User_Role
now user_role has
1. ZM
2. SBU
3. Admin
4. Normal User
user_master has
Loginid Username Role
1. XYZ 1
2. ABC 3
3. PQR 1
etc..
Now what i need is to have user role wise data
i.e.
ZM SBU Admin Normal User
XYZ NULL ABC NULL
PQR NULL NULL NULL
etc...
Please help me how it is possible..
Regards,
Krunal panchal
推荐答案
然后您可以尝试执行以下操作:
Then you can try something like this:
SELECT U.LoginID, U.UserName, R.Role FROM tbUser U LEFT OUTER JOIN tbRole ON U.UserID = R.Role
我想你明白我的意思.
--Amit
I think you got my point.
--Amit
这篇关于SQL查询,用于根据其角色分隔用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!