title: Count occurrences of ID in other columns
body: <p>I am trying to run a query which loads employee IDs, their managers (from CEO down to direct supervisor), and then a count of the number of people in their reporting group (people who they supervise either directly or indirectly). I've figured out how to do the first part, loading employee IDs and manager hierarchy.</p>
  
  <p>To simplify my question, assume the table I've created looks like:</p>
  
  <pre><code>EMPL_ID    MGR_1    MGR_2
  001        001      
  002        001      
  003        001      002
  004        001      002
  005        001      002
  006        001
  007        001      006
  </code></pre>
  
  <p>So MGR_1 is the top manager (My actual data set has thousands of rows and managers all the way down to MGR_10 but this simple example should be illustrative). The end result I want would be:</p>
  
  <pre><code>EMPL_ID    MGR_1    MGR_2    REP_GRP
  001        001               7
  002        001               3
  003        001      002      0
  004        001      002      0
  005        001      002      0
  006        001               1
  007        001      006      0
  </code></pre>
  
  <p>So REP_GRP is the count of the number of employees who report up to the person specified by EMPL_ID.</p>
  
  <p>I've tried doing this with subqueries and case statements but I can't get it to work. Any ideas?</p>