我将
Table1 (profileName,asset status,asset_Name,BaseName)
Table 2(TITLE,Role etc)
Title 链接到 table1 并使用配置文件名称
Table 3(Base_Name,Role_Id)
Base 链接到 table1 并使用 BaseName
Table 4(Role ID,Rolename)
角色 ID 链接到 table3 并使用 Role_Id)
现在我想从表 1 中获取 Role 的数据库。例如
Table 1
Test-POD AVAILABLE FOR SERVICE XYLENE Test-Base
Test-N AVAILABLE FOR SERVICE X1 Test-Base
Test-N AVAILABLE FOR SERVICE X1 Test-Base
Test-N AVAILABLE FOR SERVICE X1 Test-Base
Test-POD UNAVAILABLE FOR SERVICE XYLENE Test-Base
Test-POD UNAVAILABLE FOR SERVICE XYLENE Test-Base
Test-POD UNAVAILABLE FOR SERVICE XYLENE Test-Base
表2(有Test-POD的数据)
Test-POD Role1
Test-POD Role2
表 3(具有 Test-N 的角色 ID)
Test-Base 95D90BD1-6A31-4CB7-895A-1CDF3FBA428D(Uid)
Test-Base 95D90BD1-6A31-4CB7-895A-1CDF3FBA428D
Test-Base 95D90BD1-6A31-4CB7-895A-1CDF3FBA428D
表4
Test-Role 95D90BD1-6A31-4CB7-895A-1CDF3FBA428D
Test-Role-POD1 DCFA3F6B-066E-4C1E-858C-652520B9BABD
Test-Role-POD EF3E9A85-E709-4CD4-8F04-8570B3CBC2CC
想要根据选择的角色进行过滤。尝试下面的查询
SELECT
distinct(COUNT(Exception.asset_status)) AS CountOfasset_status1,
Exception.asset_name, Exception.asset_description
FROM
(((dbo.SATV_REP_EXCEPTION Exception
Left outer Join dbo.SATV_PROCEDURE_ROLE Proc_Role ON
(Exception.profile_name = Proc_Role.TITLE and
Proc_Role.ROLE_NAME='Test-Role-POD1'))
Left Outer Join dbo.SATV_COR_SCHEDULE_OCCURRENCE Sch_Occ on
Sch_Occ.BASE_NAME=Exception.BASE_NAME)
Left outer Join dbo.SATT_ROLES Roles ON
(Roles.ROLE_PK=Sch_Occ.ROLE_FK and
Roles.ROLE_NAME='Test-Role-POD1'))
WHERE
(Exception.ITEM_DATE > GETDATE() - 90) AND
(Exception.asset_status <> 'IN SERVICE')
AND Exception.BASE_NAME='Test-Base'
--AND (Proc_Role.ROLE_NAME='Test-Role-POD1' or Roles.ROLE_NAME='Test-Role-POD1')
GROUP BY
Exception.asset_name, Exception.asset_description,
ITEM_DATE
HAVING
(Exception.asset_name IS NOT NULL) AND
(asset_name <> '')
AND (COUNT(Exception.asset_status) > 2)
ORDER BY
CountOfasset_status1 DESC
任何帮助,将不胜感激。