2016-06-09 63 views
-1

我有以下表格:获取数据,

Websites 
-------- 
Resource (Auto incrementing primary key) 
Name 
URL 
group_id (ID of group of people website belongs to) 

WebsitePermissions 
------------------ 
Resource_id (Referencing resource in Websites table) 
GroupMember_ID (Reference to a user in group) 
Is_allowed (true/false) 

该系统基本工作原理如下:

有一个“组“的人,组管理员可以在控制面板中创建x个网站,分配明显的值

然后,管理员可以查看组中的其他人,并启用/禁用查看/使用该功能的功能网站说,开/关开关。默认值是关闭的。

每个用户只需要能够查询“所有资源与组ID(我的组ID)”,但有一个额外的字段,检查权限表,看看是否有1:行,根本不空即管理员并没有改变任何东西,2:如果有一个排,返回真/假允许该用户

所以理想的输出将是X的用户:

Resource  Name   URL   Group_id IS_ALLOWED 
    1  Google Google.co.uk   17   TRUE 

回答

0

我认为这符合您的标准:

Select wb.Resource, wb.Name, wb.URL, wb.group_id, wperm.Is_allowed from 
     Websites wb inner join WebsitePermissions wperm on wb.Resource = wperm.Resource_id 
     where GroupMember_ID = <insert your group member's ID here> 
     and wperm.Is_allowed = true