-------------------现在的!
--调度员工作量统计
-- 
-- DECLARE @BeginTime DATETIME
-- DECLARE @EndTime datetime
-- SET @BeginTime = '2005-07-28 00:00:00'
-- SET @EndTime = '2006-12-01 00:00:00'SET NOCOUNT ONdeclare @TA table(调度员 varchar(12),恶意次数 int,派车次数 int,正常完成 int,中止任务 int)
insert into @TAselect 调度员 = tt.责任调度人编码,
恶意次数 = sum(case when tal.通话类型编码 = 6 then 1 else 0 end),
派车次数 = (count(distinct(case when tt.出车结果编码 <> 1 then tt.任务编码 end))),
正常完成 = (count(distinct(case when tt.出车结果编码 in (3,4) then tt.任务编码 end))),
中止任务 = (count(distinct(case when tt.出车结果编码 = 2 then tt.任务编码 end))) from Ttask tt
 left join TAlarmEvent tae on tae.事件编码 = tt.事件编码
 left join TAlarmCall tal on tal.事件编码 = tt.事件编码
 
where tae.首次受理时刻 >=@BeginTime and tae.首次受理时刻 <=@EndTime
      and tae.事件性质编码 <>10group by tt.责任调度人编码declare @TB table(调度员 varchar(12),呼救次数 int,接听次数 int)
insert into @TBselect 调度员 = tll.调度员工号,
呼救次数 = sum(case when tll.震铃时刻 is not null then 1 else 0 end),
接听次数 = sum(case when tll.通话时刻 is not null then 1 else 0 end) from Ttellog tllwhere tll.通话时刻 >=@BeginTime and tll.通话时刻 <=@EndTime
and tll.记录类型编码 <> 6group by tll.调度员工号declare @TC table(调度员 varchar(12),完整任务 int,空车 int,完整_抢救次数 int,完整_转院次数 int)
insert into @TCselect 调度员 = tt.责任调度人编码,
完整任务 = count(distinct(case when tcr.已收标志编码 = 1 and tt.出车结果编码 = 4 then (tpr.任务编码 + convert(varchar(1),tpr.序号)) end)),
空车 = count(distinct(case when tt.出车结果编码 in (3,4) then (tpr.任务编码 + convert(varchar(1),tpr.序号)) end)) - 
count(distinct(case when tcr.已收标志编码 = 1 and tt.出车结果编码 = 4 then (tpr.任务编码 + convert(varchar(1),tpr.序号)) end)),
完整_抢救次数 = count(distinct(case when tcr.已收标志编码 = 1 and tt.出车结果编码 = 4 and tae.事件类型编码 = 2 then (tpr.任务编码 + convert(varchar(1),tpr.序号)) end)),
完整_转院次数 = count(distinct(case when tcr.已收标志编码 = 1 and tt.出车结果编码 = 4 and tae.事件类型编码 in (3,5) then (tpr.任务编码 + convert(varchar(1),tpr.序号)) end)) from TTask tt
 left join TAlarmEvent tae on tae.事件编码 = tt.事件编码
 left join TPatientRecord tpr on tpr.任务编码 = tt.任务编码
 left join TchargeRecord tcr on tpr.任务编码 = tcr.任务编码 and tpr.收费序号 = tcr.收费序号where tae.首次受理时刻 >=@BeginTime and tae.首次受理时刻 <=@EndTime
and tae.事件性质编码 <>10group by tt.责任调度人编码select 调度员 = tp.姓名,
呼救次数 = isnull(b.呼救次数,0),
接听次数 = isnull(b.接听次数,0),
恶意次数 = isnull(a.恶意次数,0),
派车次数 = isnull(a.派车次数,0),
正常完成 = isnull(a.正常完成,0),
完整任务 = isnull(c.完整任务,0),
空车 = isnull(c.空车,0),
中止任务 = isnull(a.中止任务,0),
完整_抢救次数 = isnull(c.完整_抢救次数,0),
完整_转院次数 = isnull(c.完整_转院次数,0) from Tperson tp
 left join @TA a on a.调度员 = tp.编码
 left join @TB b on b.调度员 = tp.编码
 left join @TC c on c.调度员 = tp.编码where tp.实力种类编码 = 0union all
select 调度员 = '合计',
呼救次数 = sum(isnull(b.呼救次数,0)),
接听次数 = sum(isnull(b.接听次数,0)),
恶意次数 = sum(isnull(a.恶意次数,0)),
派车次数 = sum(isnull(a.派车次数,0)),
正常完成 = sum(isnull(a.正常完成,0)),
完整任务 = sum(isnull(c.完整任务,0)),
空车 = sum(isnull(c.空车,0)),
中止任务 = sum(isnull(a.中止任务,0)),
完整_抢救次数 = sum(isnull(c.完整_抢救次数,0)),
完整_转院次数 = sum(isnull(c.完整_转院次数,0))from @TA a left join @TB b on b.调度员 = a.调度员
 left join @TC c on c.调度员 = a.调度员SET NOCOUNT OFF----原来的!--调度员工作量统计--DECLARE @BeginTime DATETIME
--DECLARE @EndTime datetime
--SET @BeginTime = '2005-5-15 0:0:0'
--SET @EndTime = '2006-5-16 0:0:0'SET NOCOUNT ONdeclare @T table(调度员 varchar(12),呼救次数 int,接听次数 int,骚扰次数 int)
insert into @Tselect  调度员 = tp.姓名,
 呼救次数 = sum(case when tll.呼入时刻 is not null then 1 else 0 end),
 接听次数 = sum(case when tll.结果编码 = 4 then 1 else 0 end),
 骚扰次数 = sum(case when tll.记录类型编码 = 4 then 1 else 0 end) from Ttellog tll
 left join Tperson tp on tll.调度员工号 = tp.编码
group by tp.姓名
--调派:中止任务,正常完成,放空车,受理:再加上拒绝出车
declare @TC table(调度员 varchar(12),受理次数 int,调派次数 int,恶意次数 int,其中空车次数 int,其中抢救次数 int,其中转运次数 int)
insert into @TCselect  调度员 = tp.姓名,
 受理次数 = sum(case when tt.出车结果编码 <> 1 then 1 else 0 end), 
 调派次数 = sum(case when tt.出车结果编码 in (2,3,4) then 1 else 0 end),
 恶意次数 = sum(case when tal.通话类型编码 = 6 then 1 else 0 end),
 其中空车次数 = sum(case when tt.出车结果编码 = 3 then 1 else 0 end),
 其中抢救次数 = sum(case when tae.事件类型编码 = 2 then 1 else 0 end),
 其中转运次数 = sum(case when tae.事件类型编码 in (3,5) then 1 else 0 end) from Ttask tt
 left join TAlarmCall tal on tal.事件编码 = tt.事件编码
 left join TacceptEvent tac on tt.事件编码 = tac.事件编码
 left join TAlarmEvent tae on tae.事件编码 = tt.事件编码
 left join Tperson tp on tp.编码 = tt.责任调度人编码
inner join TpatientRecord tpr on tpr.任务编码 = tt.任务编码
 left join TChargeLink tcl on tcl.任务编码 = tpr.任务编码 and tcl.收费序号 = tpr.收费序号
 left join TchargeRecord tcr on tpr.收费序号 = tcr.收费序号  and tpr.任务编码 = tcr.任务编码 where tac.开始受理时刻 >=@BeginTime and tac.开始受理时刻 <@EndTime
      and tae.事件性质编码 <>10group by tp.姓名declare @TD table( 调度员 varchar(12),呼救次数 int,接听次数 int,恶意骚扰次数 int,受理次数 int, 调派次数 int,其中空车次数 int,其中抢救次数 int,其中转运次数 int)
insert into @TDselect  调度员 = tc.调度员,
 呼救次数 = t.呼救次数,
 接听次数 = t.接听次数,
 恶意骚扰次数 = t.骚扰次数 + tc.恶意次数,
 受理次数 = tc.受理次数, 
 调派次数 = tc.调派次数,
 其中空车次数 = tc.其中空车次数,
 其中抢救次数 = tc.其中抢救次数,
 其中转运次数 = tc.其中转运次数 from @T t,@TC tc
where isnull(t.调度员,'') = tc.调度员insert into @TD
select   调度员 = '合计',
 呼救次数 = sum(t.呼救次数),
 接听次数 = sum(t.接听次数),
 恶意骚扰次数 = sum(t.骚扰次数) + sum(tc.恶意次数),
 受理次数 = sum(tc.受理次数), 
 调派次数 = sum(tc.调派次数),
 其中空车次数 = sum(tc.其中空车次数),
 其中抢救次数 = sum(tc.其中抢救次数),
 其中转运次数 = sum(tc.其中转运次数) from @T t,@TC tc
where isnull(t.调度员,'') = tc.调度员select * from @TDSET NOCOUNT OFF为什么我改后我的EXCEL 写的统计就得不到数据集了呢?呵呵!!!

解决方案 »

  1.   

    还以为是非技术贴呢。 走错地方了。
      

  2.   

    ----------- 第一次:
    调度员          呼救次数        接听次数        恶意骚扰次数      受理次数        调派次数        其中空车次数      其中抢救次数      其中转运次数      
    ------------ ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 
    蔡香梅          10452       9243        0           334         334         5           234         96
    郑雯英          8401        7363        0           227         227         5           181         34
    钟纯           8603        7504        0           353         353         3           220         131
    合计           27456       24110       0           914         914         13          635         261
      

  3.   

    帖错了!!!!对不起!!!