建一个临时表 ,根据临时表的内容进行更新
数据表table1中有四个字段:id,a,b,c
id为自动id,a为成绩,b为姓名,c为排名
SELECT (SELECT COUNT(DISTINCT id)
FROM table1
WHERE a > hai.a) + 1 AS 排名,id
INTO #tableTemp
FROM table1 hai
ORDER BY 排名
go
UPDATE table1
SET c = #tableTemp.排名
from table1,#tableTemp
WHERE table1.id = #tableTemp.id
SqlConnection conn = Sqlconnection(这里你自已去写)
SqlCommand mycomm = new SqlCommand("select * from 表名 order by 积分 desc",conn);
SqlDataReader dr;
conn.open();
dr=mycomm.ExecuteReader();
while(dr.Read())
{
int i = 1;
SqlCommand mycomm = new SqlCommand("update 表名 set 排名='"+i+"'",conn);
conn.Close();
conn.Open();
int y = mycomm.ExecuteNonQuery();
if(y>0)
{
MessageBox.Show("修改成功");
}
i++;
conn.Close();