以下
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 valueFROM 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----------- ----------- -----11TRUE12FALSE13TRUE21TRUE
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)