拜托了:)没看懂你的算法,解释一下. 。 假如2人level相同,每人计数1/2 加入3人level相同,每人计数1/3 丁 2 1/3 是怎么来的? 我看懂了哈哈哈 甲、乙、丁都有leve2,所以三人均计1/3 SQL code: SELECT T1.*,'1/'+T2.TOTAL from TB T1 INNER JOIN ( SELECT LEVEL,COUNT(DISTINCT [NAME]) 'TOTAL' from TB ) T2 ON T1.LEVEL=T2.LEVEL
TB是表名 SQL code: if not object_id('tb') is null drop table tb Go Create table tb([id] int,[name] nvarchar(1),[level] int) Insert tb select 1,N'甲',1 union all select 2,N'甲',2 union all select 3,N'乙',1 union all select 4,N'乙',2 union all select 5,N'乙',3 union all select 6,N'丁',2 Go Select [name], [level], [count]=ltrim(1)+'/'+ltrim((select count(*) from tb where [level]=t.[level])) from tb t /* name level count ---- ----------- ------------------------- 甲 1