解决方案 »
- 用ASP.NET开发web网站中关于datalist的问题。
- 请教高手存储过程调用及返回问题
- c# socket tcp 根据发送信息内容 判断*RS,xxxxxxxxx *TS,yyyyyyyyy 当ID条件xxxxxxxx=yyyyyyy成立
- 【急】关于SMTP发送邮件的问题
- 急求一个c#在线答题页面代码
- 学习ASP.NET之前要先学习C#吗?
- 求助:红外端口编程中,使用程序打不开端口。
- 我用什么语句可以得到SQL2000的一个表中某一列的类型
- C# 关于Jmail 发送html邮件的问题?
- 一個已給廣泛討論過的話題:合計datagrid中的數據
- 能否给个用线程控制循环的例子(实在是没分了包涵下)
- 求教 对象序列化与反序列化 的问题
我的表结构:
ID(主键) studentNo courseNo score
1 01 2001 99
2 01 2002 98
3 01 2003 97
4 02 2001 95
5 02 2002 94
6 02 2003 93
查询结果
studentNo 2001 2002 2003
01 99 98 97
02 95 94 93 方法1:
declare @s varchar(8000)
set @s=@s+',['+cast(courseNo as varchar)+']=sum(case courseNo when '''+cast(courseNo as varchar)+''' then score end)'
from 表
group by courseNo
exec('select studentNo'+@s+' from 表 group by studentNo')
方法2:
select studentNo
,[2001]=sum(case courseNo when '2001' then score end)
,[2002]=sum(case courseNo when '2002' then score end)
,[2003]=sum(case courseNo when '2003' then score end)
from 表
group by studentNo