So I have a giant table of 100K employees. Every employee has a supervisor except our top boss.
I want to capture a manager's level from the bottom. Sounds simple but now I have a series of views created at every single level - 9 times.
Example
SELECT DISTINCT
reports__allmanagers.supervisorid
FROM
reports__allmanagers
SELECT
ldap_large.uid,
ldap_large.mail,
ldap_large.jobcode,
ldap_large.thomsjobcodedescr,
ldap_large.supemail,
ldap_large.thomssupervisorid,
CASE
WHEN uid LIKE '9999' THEN '9999'
ELSE '2'
END as man_level
FROM
reports_man2ids
INNER JOIN ldap_large ON reports__man2ids.supervisorid = ldap_large.uid
This is just the two views for level 2. At the end I combine the views via a query and form a static daily table. It works but is highly highly inefficient. Is there an easier way to do this?
(The other issue I have when doing this is that our company isn't a perfect tree. So in my views a few supervisors sneak in to 2-3 different levels. In the end I need there to be only one row for each supervisor. So obviously uppermanagement will be level one one first view so we just discard the lower man_levels.)