`
flyleave
  • 浏览: 72344 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

数据库SQL语句求教

阅读更多
问题如下:有学历表一张,包含了所有人的学历信息,具体如下表所示
     Id (标示) gonghao (工号) xuewei (学位)shijian (什么时间学习的)
     如果表中的数据如下所示,那么应该如何做一个视图,使得在一条记录内包含某个人的完整学历信息,假设最高就三个学历 (学士、硕士、博士)
mysql> select * from xl;
+----+---------+--------+-----------+
| id | gonghao | xuewei | shijian   |
+----+---------+--------+-----------+
|  1 | 0722    | 学士   | 2000-2004 |
|  2 | 0722    | 硕士   | 2004-2007 |
|  4 | 0001    | 学士   | 2000-2004 |
|  5 | 0722    | 博士   | 2008-2009 |
+----+---------+--------+-----------+



求SQL 语句将上表做成如下视图

0722    | 学士   | 2000-2004 |硕士   | 2004-2007 |博士   | 2008-2009 |
0001    | 学士   | 2000-2004 |           
分享到:
评论
1 楼 reno_k 2008-01-24  
select x1.gonghao,x1.xuewei 学士,x1.shijian 时间,x2.xuewei 硕士,x2.shijian 时间,x3.xuewei 博士,x3.shijian 时间 from
xl x1 left join xl x2 on x1.gonghao=x2.gonghao and x2.xuewei='硕士'
left join xl x3 on x1.gonghao=x3.gonghao and x3.xuewei='博士'
where x1.xuewei='学士'
汗.....现在入门的东西不简单啊,花了偶不少时间,呃....

相关推荐

Global site tag (gtag.js) - Google Analytics