您不需要工会。只需离开工作室即可加入项目,然后使用合并
以下
WITH g_studio_UsersInRole AS --Sampledata
(
SELECT 1 userId ,1 roleId , 'TRUE' value
UNION SELECT 1, 2, 'TRUE'
UNION SELECT 1, 3, 'TRUE'
UNION SELECT 2, 1, 'FALSE')
, g_project_UsersInRole as --Sampledata
(
SELECT 1 userId , 2 roleId , 'FALSE' value , 1 projectId
UNION SELECT 2, 1, 'TRUE', 1
)
SELECT
sRole.userId,
sRole.roleId,
COALESCE(pRole.Value,sRole.value) as value
FROM
g_studio_UsersInRole sRole
LEFT JOIN g_project_UsersInRole pRole
ON sRole.userId = pRole.userId
and sRole.roleId = pRole.roleId
and pRole.ProjectId = 1
返回以下结果
userId roleId value
----------- ----------- -----
1 1 TRUE
1 2 FALSE
1 3 TRUE
2 1 TRUE