连锁店日交易统计表结果如下:
店ID 交易金额 交易日期
001  500     20080102
001  640     20080103
`````````````````````
005  840     20080206
007  550     20080108现在需要用一条SQL语句求出 最近三个月内,每个网点,每个月里面,交易金额最大的3天 
那位大侠做过这方面的项目 指导小弟一下啊 

解决方案 »

  1.   

    select *
    from 
    (
    select 店ID ,交易日期,row_number() over(partition by 店ID ,交易日期 order by 交易金额 desc) rn
    from a) aa
    where aa.rn rn <4
      

  2.   

    上面的有点错误
    select * 
    from  

    select 店ID ,交易日期,row_number() over(partition by 店ID ,to_char(交易日期,'yyyymm') order by 交易金额 desc) rn 
    from a ) aa 
    where aa.rn rn  <4
      

  3.   

    select 店ID,imonth,irow
    from (
    select 店ID,imonth,ROW_NUMBER() over(PARTITION BY imonth ORDER BY isum) irow
    from (select 店ID ,substr(交易日期,0,6) imonth,sum(交易金额) isum
    from 日交易统计表
    where substr(交易日期,0,6)>to_char(sysdate-90,'yyyymm')
    group by 店ID,交易日期) a)b
    where irow<=3
      

  4.   


    select * 
    from  

    select 店ID ,交易日期,row_number() over(partition by 店ID ,to_char(交易日期,'yyyymm') order by 交易金额 desc) rn 
    from a ) aa 
    where aa.rn  <4
    最后多写了个RN