谢谢,但可能是我没有说清楚,详细的表肯定另外建好了的,但,怎么样才能把表中的
内容提升为表头呢?
我们常用的SQL语句都是表头就是表头,字段值就是字段值,在ACCESS中可以跨越这道鸿沟,可,SQL SERVER中不支持TRANSFORM ,PIVOT语句啊,我该如何实现???
内容提升为表头呢?
我们常用的SQL语句都是表头就是表头,字段值就是字段值,在ACCESS中可以跨越这道鸿沟,可,SQL SERVER中不支持TRANSFORM ,PIVOT语句啊,我该如何实现???
select distinct stuid,
(select grade from stugrade where stuid=c.stuid and courseid='语文') as '语文',
(select grade from stugrade where stuid=c.stuid and courseid='数学') as '数学',
(select grade from stugrade where stuid=c.stuid and courseid='历史') as '历史'
from stugrade c
反正偶是看不懂,嘿嘿
select @subject=subject from maindb
exec('select * from ' + @subject + ');另外,数据库结构设计合理以后,完全不需要搞得这么麻烦,还是下功夫在如何避免出现交叉数据的问题吧。
select stuid,
sum(case courseid when '语文' then grade else 0) as '语文',
sum(case courseid when '数学' then grade else 0) as '数学',
sum(case courseid when '历史' then grade else 0) as '历史'
from stugrade c
group by stuid
select stuid,
sum(case courseid when '语文' then grade else 0 end) as '语文',
sum(case courseid when '数学' then grade else 0 end) as '数学',
sum(case courseid when '历史' then grade else 0 end) as '历史'
from stugrade c
group by stuid
没见你的姓名字段在哪里啊。