insert into t select 'C001', 'Mary'
union select 'C006', 'Micke'
union select 'C003', 'Nike'
union select 'C001-1','asdfasd'
union select 'C001-2','gwfa'
select (select count(*)
from t
where CustomerCode<=a.CustomerCode ) as AutoCol,
CustomerCode,
CustomerName
from t a
order by CustomerCode
create table t(CustomerCode varchar(20), CustomerName varchar(20))
insert into t select 'C001', 'Mary'
union select 'C006', 'Micke'
union select 'C003', 'Nike'
select (select count(*)
from t
where CustomerName<=a.CustomerName ) as AutoCol,
CustomerCode,
CustomerName
from t a
order by customername
--结果
1 C001 Mary
2 C006 Micke
3 C003 Nike