title: How to join two tables and do mathematical calculations
body: <p>I have two tables, EmployeeDetails and CompOffTable. I want to add rows of CompOff table and the result i get on the count of each row should be added to a column to EmployeeDetails table. I have used Left Out Join. Please Help me with this code.</p>
  
  <pre><code>SELECT 
    a.EmpID, 
    a.EmpName, 
    a.Department, 
    a.Designation, 
    a.TotalLeaves, 
  COUNT(b.EmpName) AS TotalCompOff                         
  FROM (EmployeeDetails a LEFT OUTER JOIN
  (CompOffTable b ON a.EmpName = b.EmpName) 
  INNER JOIN SUM(a.TotalLeaves + TotalCompOff) AS RemainingLeaves )                        
  GROUP BY a.EmpID, a.EmpName, a.Department, a.Designation, a.TotalLeaves
  </code></pre>