sql  语句
statTime(时间) num(号码) kind(业务类型)
2008-5-1       131          A
2008-5-1       132          A
2008-5-1       133          A
2008-5-1       134          A
2008-5-2       131          B
2008-5-2       132          B
2008-5-2       133          B
2008-5-2       134          B
 在按日期统计 号码的时候,5。1为4,5。2也为4,
现在有个需求消除重复,就是如果在5。1出现的号码如果在5。2出现,在统计5。2就不算,怎么实现

解决方案 »

  1.   

    select count(num) from (select distinct num,statTime from 表) group by statTime看行不 哈      
      

  2.   

    select count(num) from tablename where num not in (select distinct num from tablename)
    不知道是不是这个意思
      

  3.   

    select a.statTime,sum(a.cnt)-nvl(sum(b.cnt),0) from
    (select statTime,num,count(*) cnt from 表名 group by statTime,num) a
    left outer join
    (select statTime,num,count(*) cnt from 表名 group by statTime,num) b
    on b.statTime=a.statTime and b.num=a.num
    and b.num in (select num from 表名 where statTime<a.statTime)
    group by a.statTimeOracle 下测试通过,这个会按照你的要求,5.1 统计全,5.2统计除去5.1相同num的,5.3统计除去与5.1,5.2相同num的,依次类推,楼主看看吧,hehe