0

我有一个主管表,工作日数=5。我也有一个缺席的表。现在我从两个表中计算现在的天数。如何得到这个。

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

现在我想得到这个

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

4 回答 4

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

SQL小提琴

于 2013-05-15T05:55:53.443 回答
0

请参阅以下查询:

select p.Suplist,(p.WorkDays-a.AbsentDays) as PresentDays 
from presentTable p,absentTable a 
where p.Suplist=a.Suplist
于 2013-05-15T05:58:11.927 回答
0

我认为您需要一个外部连接,以便如果一个人不缺席,那么您也可以为他提供当前天数。

Select s.Suplist , (s.workDays - nvl(a.absentDays,0)) as PresentDays
from supervisortable s
left outer join absentTable a
on s.suplist=a.suplist
于 2013-05-15T05:58:42.313 回答
0

请试试:

select 
    a.SupList, 
    a.WorkDays-isnull(b.AbsentDays,0) PresentDays
from 
    Supervisor a LEFT JOIN Absent b on a.SupList=b.Suplist
于 2013-05-15T06:00:10.250 回答