请问一个SQL 问题:怎么将以下用sql语句将竖改为横

[复制链接]
查看11 | 回复2 | 2009-2-24 09:53:31 | 显示全部楼层 |阅读模式
name语文
英语
a
20
10
b
30
20
c
40
30
显示结果为:
name
a
b c
语文
20 30 40
英语
10 20 30
用sql语句写
不行啊,你们这两个都不行,实际的表:create table stuMarks
(
ExamNochar(7) not null,
stuNo nvarchar(20) not null,
writtenExam intnot null ,
LabExam
intnot null
)
Insert stumarks
select N's25301',50,78 union all
select N's25302',56,68 union all
select N's25303',79,87 union all
select N's25304',90,58

回复

使用道具 举报

千问 | 2009-2-24 09:53:31 | 显示全部楼层
select '语文' as name,
sum(case name when 'a' then 语文 else 0 end) as a,
sum(case name when 'b' then 语文 else 0 end) as b,
sum(case name when 'c' then 语文 else 0 end) as c from 表uionselect '英语' as name,
sum(case name when 'a' then 英语 else 0 end) as a,
sum(case name when 'b' then 英语 else 0...
回复

使用道具 举报

千问 | 2009-2-24 09:53:31 | 显示全部楼层
http://hi.baidu.com/lz0830/blog/item/aaabfa1720a8a0064a90a7ee.html...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行