我不知道你的时间和时间段的对应关系,先假设每个单独的时间点就是一个时间段,然后可以这样来实现:
insert into tab_2 select calli,callp,time,count(*),sum(decode(flag,'成功',1,0)),
count(*)-sum(decode(flag,'成功',1,0))  from tab_1  group by calli,callp,time;

解决方案 »

  1.   

    假设查询时间段为2005-01-01  -- 2005-06-01,表1中flag标志0表示失败,1表示成功
    那么一条SQL语句就足够了:insert into 表2
    select
        calli,
        callp,
        period = '2005-01-01  -- 2005-06-01',
        callsum = count(*),
        failsum = sum(decode(flag,0,1,0)),
        sucsum  = sum(decode(flag,1,1,0))
    from
        表1
    where
        time between to_date('2005-01-01','YYYY-MM-DD') and to_date('2005-06-01','YYYY-MM-DD')
    group by
        calli,callp