2016-06-09 26 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