title: How to work with Table joins and Inline View
body: <p>Can anyone help me to understand this SQL query; I don't understand the concept behind it:</p>
  
  <pre><code>SELECT
      t2.*,
      (
          SELECT SUM (salary)
          FROM (
              SELECT
              tb1.*, 
              ROWNUM AS rnk
              FROM ( 
                  SELECT *
                  FROM employees e
                  ORDER BY E.DEPARTMENT_ID, E.EMPLOYEE_ID
              ) tb1
          ) tb2
          WHERE   tb2.DEPARTMENT_ID = t2.DEPARTMENT_ID AND tb2.rnk &lt;= t2.rnk
      ) dept_salary
  FROM (
      SELECT   
          t1.*, 
          ROWNUM AS rnk
      FROM (  
          SELECT   
              e.employee_id,
              e.first_name,
              e.department_id,
              e.salary
          FROM employees e
          ORDER BY   E.DEPARTMENT_ID, E.EMPLOYEE_ID
      ) t1
  ) t2
  </code></pre>