table1
a b c d e  f
1 1 1 0 aa x
1 1 1 0 bb x
1 1 1 0 cc z
1 1 1 1 aa z
1 1 1 1 bb y
1 1 1 1 cc y
table2 
f g
x ssss
y gggg
z wwww
查询结果为 
a b c d e  f     seqno
1 1 1 0 aa ssss  1
1 1 1 0 bb ssss  2
1 1 1 0 cc wwww  3
1 1 1 1 aa wwww  1 
1 1 1 1 bb gggg  2
1 1 1 1 cc gggg  3
根据table1中字段 a,b,b,c来编号,只要其中一个改变后,编号重新从1开始

解决方案 »

  1.   

    select a,b,c,d,e,t1.f,g row_number() over(partition by a,b,c,d order by e desc)
    from t1,t2
    where t1.f=t2.f
      

  2.   

    select a.a,a.b,a.c,a.d,a.f,row_number() over(partition by a.seqno order by a.seqno)from
    (select t1.a a,t1.b b,t1.c c,t1.d d,t1.e e,t2.g f,
    t1.a||t1.b||t1.c||t1.d seqno
    from table1 t1,table2 t2
    where t1.f=t2.f) a
      

  3.   

    改造了一下:
    select * from
    (select t1.a a,t1.b b,t1.c c,t1.d d,t1.e e,t2.g f,
    row_number() over(partition by t1.a | |t1.b | |t1.c | |t1.d order by t1.a | |t1.b | |t1.c | |t1.d) seqno
    from table1 t1,table2 t2
    where t1.f=t2.f) a
      

  4.   

    select table1.a,table1.b,table1.c,table1.d,table1.e,table1.f,table2.g,row_number() over (partition by table1.a,table1.b,table1.c,table1.d order by table1.e desc) as seqno
    from table1, table2  
    where table2.f = table1.f;