如有一张表有以下两个字段
  交易日期  账号 比如 每做一笔交易就会插入一条记录
如何查询从今以来 每3日内交易次数超过10次的账号及三日内交易的次数啊?

解决方案 »

  1.   


    SELECT 账号,COUNT(*) FROM YOURABLE WHERE 日期>(trunc(sysdate)-3) GROUP by 账号 having count(*)>10 
      

  2.   

    用sql想不到方法,期待高手或你用过程 写
      

  3.   

    记得以前有个类似的问题
    select c.账号,min(c.交易日期) 起始日期,count(*) from tab c, 
      (select 账号,min(交易日期) as rq from 
          (select a.账号,a.交易日期 from tab a,tab b where (a.账号 = b.账号) and (b.交易日期 between a.交易日期 and a.交易日期 + 3) 
            and (a.交易日期 between to_date('20090101','yyyymmdd') and to_date('20091231','yyyymmdd')) 
            group by a.账号,a.交易日期 having count(*) > 10) 
        group by 账号) d 
    where c.账号 = d.账号 and (c.交易日期 between d.交易日期 and d.交易日期 + 3) group by c.id; 
    红色部分为自定义时间段
      

  4.   

    最后是 group by c.账号 ,上面写错了