|
本帖最后由 djt 于 2009-9-28 09:02 编辑
首先把记录维护好,H-5和H-05的排列顺序绝对不一样
SELECT tt1.*, 'V' & Format(SortNo,'0000') AS 新号
FROM 表1 AS tt1 inner JOIN (select t1.字段1,t1.字段2,count(*) as SortNo
from (select 字段1,字段2,字段1&字段2 as nr from 表1 group by 字段1,字段2) as t1 inner join (select 字段1,字段2,字段1&字段2 as nr from 表1 group by 字段1,字段2) as t2 on t1.nr>=t2.nr
group by t1.字段1,t1.字段2) AS tt2 ON (tt1.字段1 = tt2.字段1) AND (tt1.字段2 = tt2.字段2)
ORDER BY 'V' & Format(SortNo,'0000')
编号 字段1 字段2 新号
1 A0001 H-01 V0001
7 A0001 H-04 V0002
6 A0001 H-05 V0003
11 A0001 H-10 V0004
12 A0001 H-11 V0005
3 B0002 H-02 V0006
5 B0002 H-03 V0007
8 B0002 H-06 V0008
9 B0002 H-07 V0009
10 B0002 H-09 V0010
13 B0002 H-12 V0011
14 B0002 H-13 V0012
18 B0002 H-14 V0013
15 B0002 H-14 V0013
16 B0002 H-14 V0013
17 B0002 H-14 V0013
|
|