日期:2014-05-18 浏览次数:20561 次
CREATE #TEMP ( ID INT IDENTITY(1,1), fenshu INT, xingming ) SELECT fenshu, xingming INTO #TEMP FROM chengji ORDER BY fenshu SELECT fenshu, xingming, mingci = '第'+str([ID])+'名' FROM #TEMP DROP #TEMP
------解决方案--------------------
select * into newtable from chengji
再在newtable里添加两列 一列叫作编号设为identity(1,1) 别一列假设叫做名次 数据类型为varchar
update newtable
set 名次='第'+str(编号)+'名'
------解决方案--------------------
刚才测试了一下,这个方法不错:
create table #t (fs int,id int identity (1,1)) insert into #t(fs) select distinct fenshu from chengji order by fenshu desc select cj.*,'第'+cast(#t.id as varchar)+'名' from chengji cj join #t on #t.fs=cj.fenshu order by #t.id drop table #t
------解决方案--------------------
你的库不好
成绩、课程、个人信息分开存放
个人表(personid,姓名)
课程表(courseid,名称)
成绩表(personid,courseid,result)
------解决方案--------------------
库名和字段名最好用英语写
------解决方案--------------------
你可以将他写的查询语句写成存储过程,然后在程式里调用存储过程就可以了,我试过了,用ID的识别名字,真的不错~~
------解决方案--------------------
存储过程
Create proc sp_SChengjiInfo AS CREATE #TEMP ( ID INT IDENTITY(1,1), fenshu INT, xingming ) SELECT fenshu, xingming INTO #TEMP FROM chengji ORDER BY fenshu SELECT fenshu, xingming, mingci = '第'+str([ID])+'名' FROM #TEMP DROP #TEMP
------解决方案--------------------
如果是想在页面上显示查询的结果,在页面上放一个gridview
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _paiming : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { Bind(); } } private void Bind() { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ToString())) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "sp_SChengJiInfo"; //指定存储过程名字 cmd.CommandType = CommandType.StoredProcedure; //指定类型为存储过程 cmd.Conn