SQL笔试题1

 

 1 已知一个表的结构为: 
 2 姓名 科目 成绩 
 3 张三 语文  20  
 4 张三 数学  30  
 5 张三 英语  50  
 6 李四 语文  70  
 7 李四 数学  60  
 8 李四 英语  90  
 9 怎样通过select语句把他变成以下结构: 
10 姓名 语文 数学 英语 
11 张三  20   30   50  
12 李四  70   60   90
答案:

posted on 2006-12-21 18:05 youngturk 阅读(3972) 评论(6)  编辑  收藏 所属分类: SQL笔试题

评论

# re: SQL笔试题1 2008-02-24 15:05 stoneyang

select sname, sum(case skemu when '语文' then sgrade else 0 end) as 语文,
sum(case skemu when '数学' then sgrade else 0 end) as 数学,
sum(case skemu when '英语' then sgrade else 0 end) as 英语
from students group by sname order by sname desc  回复  更多评论   

# re: SQL笔试题1 2008-03-10 11:59 思宽

@stoneyang
谢谢探讨  回复  更多评论   

# re: SQL笔试题1 2008-09-16 17:14 dfadsfa

select t1.姓名,t1.语文,t2.数学,t3.英语from
(select 姓名as 姓名,成绩as 语文from t where 科目='语文') t1
join
(select 姓名as 姓名,成绩as 数学from t where 科目='数学') t2
on t1.姓名=t2.姓名
join
(select 姓名as 姓名,成绩as 英语from t where 科目='英语') t3
on t2.姓名=t3.姓名
  回复  更多评论   

# re: SQL笔试题1 2009-02-24 16:24 feifeirao

楼主的,应该是这样的吧-------------------------
select A.姓名,A.成绩 as 语文,B.成绩 as 数学,C.成绩 as 英语
from student A,student B,student C
where A.姓名 = B.姓名 and B.姓名 = C.姓名
and A.科目 = ' 语文 ' and B.科目 = ' 数学 '
and C.科目 = ' 英语 '   回复  更多评论   

# re: SQL笔试题1 2009-03-19 15:44 fuchu12000

select distinct aa3.姓名,aa3.语文,aa3.数学,aa4.英语 from
(select distinct aa1.姓名,aa1.语文,aa2.数学 from
(select 姓名,成绩 as 语文 from Table_name where 科目='语文') aa1
left join
(select 姓名,成绩 as 数学 from Table_name where 科目='数学') aa2
on aa1.姓名=aa2.姓名) aa3
left join
(select 姓名,成绩 as 英语 from Table_name where 科目='英语') aa4
on aa3.姓名=aa4.姓名  回复  更多评论   

# re: SQL笔试题1 2009-05-30 11:13 sdf

select 姓名,(case when 语文 then 成绩) as 语文,(case when 数学 then 成绩) as 数学,,(case when 英语 then 成绩) as 英语 from table  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

公告

this year :
1 jQuery
2 freemarker
3 框架结构
4 口语英语

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

EJB学习

Flex学习

learn English

oracle

spring MVC web service

SQL

Struts

生活保健

解析文件

搜索

最新评论

阅读排行榜

评论排行榜