Question

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
Was it helpful?

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

OTHER TIPS

Refer Following Query:

select p.Suplist,(p.WorkDays-a.AbsentDays) as PresentDays 
from presentTable p,absentTable a 
where p.Suplist=a.Suplist

I think you need a outer join so that if a person is not absent then also you can provide the present days count for him.

Select s.Suplist , (s.workDays - nvl(a.absentDays,0)) as PresentDays
from supervisortable s
left outer join absentTable a
on s.suplist=a.suplist

Please try:

select 
    a.SupList, 
    a.WorkDays-isnull(b.AbsentDays,0) PresentDays
from 
    Supervisor a LEFT JOIN Absent b on a.SupList=b.Suplist
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top