统计每天所有人工时填写情况。
select emp, sum(hours)
from A
where emp in('a','b','c')
and month=curmonth and year= curyear
group by emp
有个问题,如果没有c的记录,将不会显示c的信息
所以用left join
select a.emp,isnull(b.hours,0)
from
(
select distinct emp
from A
where emp in('a','b','c')
)a
left join
(
select emp, sum(hours)
from A
where month=curmonth and year= curyear
group by emp
)b
on a.emp=b.emp
这样如果c没有记录,可以显示为c是0了。