--SQL2000的并列排名解决方法
--示例数据
CREATE TABLE tb(Name varchar(10),Score decimal(10,2))
INSERT tb SELECT 'aa',99
UNION ALL SELECT 'bb',56
UNION ALL SELECT 'cc',56
UNION ALL SELECT 'dd',77
UNION ALL SELECT 'ee',78
UNION ALL SELECT 'ff',76
UNION ALL SELECT 'gg',78
UNION ALL SELECT 'ff',50
GO
ASP.NET后台:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection sqlcon;
//SqlCommand sqlcom;//更新删除时要用的
string strCon = "Data Source=(local);Database=master;Uid=sa;Pwd=5354";
//string sqlstr = "SELECT *,Place=(SELECT COUNT(DISTINCT Score) FROM tb WHERE Score>=a.Score) FROM tb a ORDER BY Place";//重复时合并名次,在ACCESS2000中此语句无效
string sqlstr = "SELECT *,Place=(SELECT COUNT(Score) FROM tb WHERE Score>a.Score)+1 FROM tb a ORDER BY Place";//重复时保留名次空缺,在ACCESS2000中此语句无效
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tb");
GridView1.DataSource = myds;
GridView1.DataBind();
}
catch (Exception er)
{
Label1.Text = er.Message;
}
}