【发布时间】:2011-06-15 10:47:51
【问题描述】:
我可以加入以下3个语句以在一行中显示sick_total_day、other_total_day、other_total_day(同where子句)?
SELECT staff_key,
sum(days_applied) as sick_total_day
from Tleave_sick_leave
where staff_key = 131
and from_date>='2011/4/1 00:00:00'
and to_date<='2011/4/30 00:00:00';
SELECT staff_key,
sum(days_applied) as other_total_day
from Tleave_other_leave
where staff_key = 131
and from_date>='2011/4/1 00:00:00'
and to_date<='2011/4/30 00:00:00';
SELECT staff_key,
sum(days_applied) as other_total_day
from Tleave_vleave
where staff_key = 131
and from_date>='2011/4/1 00:00:00'
and to_date<='2011/4/30 00:00:00';
【问题讨论】:
-
您想要这些记录的联合,还是想要这些表中所有记录的记录中的
days_applied的总和?
标签: sql sql-server join