select caller,
       convert(char(7),starttime,120),
       count(*),
       sum(datediff(ms,starttime,endtime))/1000.0
from tablename
group by caller,convert(char(7),starttime,120)

解决方案 »

  1.   

    上面缺了insert into
    insert into 结算表(caller,month,times,totaltime)
    select A.caller,A.yue,A.cs,A.sumtime 
    from 
    (select caller,
           convert(char(7),starttime,120) as yue,
           count(*) as cs,
           sum(datediff(ms,starttime,endtime))/1000.0 as sumtime
    from tablename
    group by caller,convert(char(7),starttime,120)) A
      

  2.   

    sorry
    insert into 结算表(caller,month,times,totaltime)
    select A.caller,A.yue,A.cs,A.sumtime 
    from 
    (select caller,
           convert(char(7),starttime,120) as yue,
           count(*) as cs,
           sum(datediff(ms,starttime,endtime))/1000.0 as sumtime
    from tablename
    group by caller,starttime )A