RenId RenMing RenParentId
3 王一 9
4 王二 9
5 张一 10
6 张二 10
10 张父 15
15 张父父 Null
9 王父 Null
if object_id('test') is not null
drop table test
go
create table test(Renid int,RenMing nvarchar(3),RenParentId int)
insert into test select 3,N'王一',9
union all select 4,N'王二',9
union all select 5,N'张一',10
union all select 6,N'张二',10
union all select 10,N'张父',15
union all select 15,N'张父父',null
union all select 9,N'王父',null
1.
select left(RenMing,1) as 项目,count(RenMing) 人数 from test group by left(RenMing,1)
2.
select id=(select count(1) from test where Renid<t.Renid)+1,* from test t
drop table test
go





2007-4-5 23:03


