-------------------------------Secondary Role[AssessmentTime] Vs Engineer Count Vs Assessment Count-------------------------------
SELECT u.SecondaryRole
,cxr.Id AS CenterSecondaryRoleId
,count(u.UserId) AS [EngineerCountRmr]
,(
SELECT count(a.AssessmentId)
FROM dbo.Assessment a
WHERE a.IsActive = 1
AND a.CenterSecondaryRoleId = cxr.Id
) AssessmentCount
FROM dbo.[User] u
INNER JOIN dbo.SecondaryRoleMaster srm ON ltrim(rtrim(upper(u.SecondaryRole))) = ltrim(rtrim(upper(srm.NAME)))
INNER JOIN dbo.CenterXSecondaryRole cxr ON srm.Id = cxr.SecondaryRoleId
GROUP BY u.SecondaryRole
,cxr.Id
ORDER BY u.SecondaryRole
-------------------------------Secondary Role[Current] ,Participated Engineer Count-------------------------------
SELECT u.SecondaryRole
,Count(DISTINCT u.UserId) AS UniqueEngineersCount
FROM dbo.Assessment a
INNER JOIN dbo.UserCenterXCenterPguSkill ucxps ON a.UserCenterXCenterPguSkillId = ucxps.Id
INNER JOIN dbo.UserXCenter ux ON ucxps.UserXCenterId = ux.UserXCenterId
INNER JOIN dbo.[User] u ON ux.UserId = u.UserId
AND u.IsActive = 1
WHERE a.IsActive = 1
GROUP BY u.SecondaryRole
ORDER BY 1
------------------------Head Count Wave Region Country Facility Pgu Skill----------------------------------
SELECT t1.Wave
,t1.Region
,t1.Country
,t1.FacilityDesc
,t1.Pgu
,t1.SkillName
,count(DISTINCT t1.EngUserId) UniqueEngineersCount
FROM [dbo].[Generic$] t1
GROUP BY t1.Wave
,t1.Region
,t1.Country
,t1.FacilityDesc
,t1.Pgu
,t1.SkillName
ORDER BY t1.Wave
,t1.Region
,t1.Country
,t1.FacilityDesc
,t1.Pgu
,t1.SkillName