SQL语句问题
那个case和sum 那种方法是怎么用的.谢谢高手指点!
select name as 姓名, sum(语文) as 语文,sum(数学) as 数学,sum(英语) as 英语, sum(语文)+sum(数学)+sum(英语) as 总分
from
(
select name,
case course when '语文' then score else 0 end as 语文,
case course when '数学' then score else 0 end as 数学,
case course when '英语' then score else 0 end as 英语
from students
) a
group by name
order by 总分 desc
比如这个
select distinct name 姓名
,
(select score
from students a
where course='语文'
and a.name=b.name) as 语文
,
(select score
from students a
where course='英语'
and a.name=b.name) as 英语
,
(select score
from students a
where course='数学'
and a.name=b.name) as 数学
from students b
[URL=http://www.bc-cn.net/bbs/dispbbs.asp?BoardID=24&replyID=68068&id=51307&skin=0]这里[/URL]人家的问题跟你一样,不是一本教材吧
[此贴子已经被作者于2006-3-25 11:59:27编辑过]