现有一个表:ID    主叫   被叫   外呼座机(phonenumber)   开始时间(createtime)    结束时间(overtime)    时长(timelong)
现有两个话务班次,每个班是9点至第二天9点  我要查每个话务员的每个月的工作量每个话务员负责的外呼座机是固定的要求,根据 每个外呼座机号码的每天9点到第二天9点之前 查出来的时长,然后汇总。我现在的办法是
select datepart(d,createtime),phonenumber,sum(timelong) from 表名
where ((cast(datepart(d,createtime) as int )%2<>0 and datepart(hh,createtime)>8) or (
cast(datepart(d,createtime) as int )%2=0 and datepart(hh,createtime)<9))
group by datepart(d,createtime),phonenumber 
order by datepart(d,createtime),phonenumber然后手工统计每天的量,请教各位大侠,有没有更好的办法?

解决方案 »

  1.   


    /*这个,不知道我理解得对不对,似乎不需要那么复杂,你时长不是已经计算出来了么,
    如果是按分钟来计算的
    timelong=datediff(mi,createtime,overtime)
    */
    --剩下的就只用
    select id,sum(timelong)
    from tb
    gruop by id 
    --至于你是要按呼出算工作时间,还是呼出加呼入一起算,再根据条件就可以了,加上时间范围
      

  2.   

    没有看到怎么算统计的是每个话务员,难道是phonenumber
    select datepart(m,createtime),phonenumber,sum(timelong) 
    from 表名
    group by datepart(m,createtime),phonenumber  
    order by datepart(m,createtime),phonenumber
      

  3.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281