Search code examples
sqljoinsql-server-expressexcept

SQL difference Calculation from two table or views


I have a supervisor table and No. of Working Days=5.I also have a absent tabale.Now I to calculate Present Days from two table.How to get this.

 SupList    WorkDays
    101         5
    102         5
    103         5
    104         5
    105         5
 Suplist   AbsentDays
    101         2
    103         1

Now I want to get this

Suplist      PresentDays
101         3
102         5
103         4
104         5
105         5

Solution

  • Select s.Suplist , (s.workDays - isnull(a.absentDays,0)) as PresentDays
    from supervisertable s
    left join absentTable a
    on s.suplist=a.suplist
    

    SQL Fiddle