SELECT count(*), 
            CASE 
                WHEN gp.PublishedAt IS NOT NULL THEN 2 
                WHEN gp.LastActivityAt > gp.CreatedAt or cv.UpdatedAt > cv.CreatedAt THEN 1
                ELSE 0 
            END AS GrowthPlanState
            FROM Growth.develop.GrowthPlan gp 
            JOIN Growth.ec.[User] u ON u.Id = gp.OwnerId
            JOIN Analytics.survey.Users au ON au.MembershipId = u.Id
            JOIN Growth.develop.CareerVision cv on cv.UserId = u.Id
            WHERE u.OrganizationId = 166369 group by CASE 
                WHEN gp.PublishedAt IS NOT NULL THEN 2
                WHEN gp.LastActivityAt > gp.CreatedAt or cv.UpdatedAt > cv.CreatedAt THEN 1
                ELSE 0 
            END