求多条记录合并为一条记录的sql语句。 本帖最后由 laozishi110 于 2012-05-09 09:53:55 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select studentname,sum(case when course = '语文' then score else 0 end) as '语文' ,sum(case when course = '英语' then score else 0 end) as '英语' from TB group by studentname/*studentname 语文 英语----------- ----------- -----------李三 50 80王五 60 70(2 行受影响) select TF.studentname,TF.course,TF.score,TT.course,TT.scorefrom (select *from TBwhere course='语文') TFinner join (select * from TB where course='英语') TT on TT.studentname =TF.studentname/*studentname course score course score----------- ------ ----------- ------ -----------李三 语文 50 英语 80王五 语文 60 英语 70(2 行受影响) 行专列 SQL 2000用2楼SQL 2005以上select studentname,语文,英语from CourseGradepivot (max(score) for course in([语文],英语)) as d studentname 语文 英语李三 50 80王五 60 70并列显示select A.studentname,A.course,A.score,B.course,B.scorefrom CourseGrade AS A INNER JOIN CourseGrade AS B ON A.studentname = B.studentname AND A.course = '语文' AND B.course = '英语'studentname course score course score李三 语文 50 英语 80王五 语文 60 英语 70 耗时的存储过程 奇怪的“超时已过期”问题 WHERE 条件中如何动态指定,就是CASE WHEN 能不能用在WHERE 中? 怎么更改IN后面的参数 无法查看数据库属性。数据库 'WSS_CustWeb_Content' 正处于转换状态。 摆脱各位高手,急求一条分组排序sql语句! 数据库可疑,用了网上的办法也没用 三个表会两两关联,怎么办?--急!高分相送 请教,关于ODBC数据源的设置问题!!! 在SQL Server2000查询分析器中正常,delphi中Query中执行出错,为什么? sql 累加树形结构 csdn牛人多,帮帮忙 某一字段的所有记录求与
select studentname,
sum(case when course = '语文' then score else 0 end) as '语文' ,
sum(case when course = '英语' then score else 0 end) as '英语'
from TB
group by studentname
/*
studentname 语文 英语
----------- ----------- -----------
李三 50 80
王五 60 70(2 行受影响)
from
(select *
from TB
where course='语文') TF
inner join (select * from TB where course='英语') TT on TT.studentname =TF.studentname
/*
studentname course score course score
----------- ------ ----------- ------ -----------
李三 语文 50 英语 80
王五 语文 60 英语 70(2 行受影响)
SQL 2005以上select studentname,语文,英语
from CourseGrade
pivot (max(score) for course in([语文],英语)) as d studentname 语文 英语
李三 50 80
王五 60 70并列显示
select A.studentname,A.course,A.score,B.course,B.score
from CourseGrade AS A INNER JOIN CourseGrade AS B ON A.studentname = B.studentname AND A.course = '语文' AND B.course = '英语'studentname course score course score
李三 语文 50 英语 80
王五 语文 60 英语 70