select dept_code,data_index,sum(data_value) as data_value,IDENTITY (int,1 , 1 ) AS mc
into #Temp
from tablename
group by dept_code,data_index
order by sum(data_value) descselect * from #temp
into #Temp
from tablename
group by dept_code,data_index
order by sum(data_value) descselect * from #temp
From
(Select COUNT(*) From (Select dept_code,data_index,sum(data_value) as data_value )
as t2
From
(Select dept_code,data_index,sum(data_value) as data_value )
as t2
101 3 1000 1
102 5 888 2
103 9 888 2
104 10 600 4所以改为
Select 1+(Select COUNT(*) From (Select dept_code,data_index,sum(data_value) as data_value ) AS t1 Where T1.data_value<t2.data_value ) as 名次, *
From
(Select dept_code,data_index,sum(data_value) as data_value )
as t2
我试了用RowID,但还是不行。