• Find the ID, names of all the students from departments whose name contain character ‘功’.
mysql> select id, name, dept_name from student where dept_name like '%功%';
+-------+--------+-----------+
| id    | name   | dept_name |
+-------+--------+-----------+
| 00128 | 丘处机 | 内功学院  |
| 12345 | 段誉   | 内功学院  |
| 54321 | 杨过   | 内功学院  |
| 76543 | 段正淳 | 内功学院  |
+-------+--------+-----------+
4 rows in set
  • Find the ID, names and total credits of students in 邪门学院 department or in 兵器学院 department whose total credits are higher than 50 credits.
//AND和OR的优先级:AND > OR, 去掉括号结果错误!!!
mysql> select id, name, tot_cred,dept_name-> from student-> where (dept_name='邪门学院' or dept_name='兵器学院') and tot_cred>50;
+-------+--------+----------+-----------+
| id    | name   | tot_cred | dept_name |
+-------+--------+----------+-----------+
| 19991 | 林平之 | 80       | 兵器学院  |
| 23121 | 穆念慈 | 110      | 兵器学院  |
| 44553 | 蓝凤凰 | 56       | 邪门学院  |
| 76653 | 胡斐   | 60       | 兵器学院  |
| 98765 | 李莫愁 | 98       | 兵器学院  |
+-------+--------+----------+-----------+
5 rows in set
  • For the instructor 83821, show course_id and title of all courses taught by the instructor.
mysql> select course.course_id, title, sec_id-> from course, teaches-> where course.course_id = teaches.course_id and id='83821';
+-----------+----------+--------+
| course_id | title    | sec_id |
+-----------+----------+--------+
| cn2       | 九阴真经 | 1      |
| cn2       | 九阴真经 | 2      |
| cn4       | 易筋经   | 2      |
+-----------+----------+--------+
3 rows in set
  • As above, but show the total number of credits for such courses (taught by that instructor). You should use SQL aggregation on courses taught by that instructor.
mysql> select course.course_id, title, sum(credits)-> from course, teaches-> where course.course_id=teaches.course_id and id='83821'-> group by course.course_id, title;
+-----------+----------+--------------+
| course_id | title    | sum(credits) |
+-----------+----------+--------------+
| cn2       | 九阴真经 | 8            |
| cn4       | 易筋经   | 3            |
+-----------+----------+--------------+
2 rows in set
  • As above, but display the total credits for each of the instructors, along with the ID of the instructor; don’t bother about the name of the instructors. (Don’t bother about instructors who have not taught any course, they can be omitted)
mysql> select id, sum(credits)-> from teaches, course-> where course.course_id=teaches.course_id-> group by id;
+-------+--------------+
| id    | sum(credits) |
+-------+--------------+
| 10101 | 10           |
| 12121 | 3            |
| 15151 | 3            |
| 22222 | 4            |
| 32343 | 3            |
| 45565 | 7            |
| 76766 | 8            |
| 83821 | 11           |
| 98345 | 3            |
+-------+--------------+
9 rows in set
  • Find average instructors’ salaries for each of courses, along with the course_id and title of the course, taught by instructors of 内功学院, the result should be sorted from the lowest to the highest according to the average salaries.
mysql> select course.course_id, title, avg(salary)-> from course, instructor, teaches-> where instructor.id=teaches.id and teaches.course_id=course.course_id and instructor.dept_name='内功学院'-> group by course.course_id, title-> order by avg(salary);
+-----------+----------+-------------+
| course_id | title    | avg(salary) |
+-----------+----------+-------------+
| cn5       | 太极     | 65000       |
| cn3       | 九阳神功 | 65000       |
| cn1       | 内功基础 | 70000       |
| cn4       | 易筋经   | 83500       |
| cn2       | 九阴真经 | 92000       |
+-----------+----------+-------------+
5 rows in set
  • Find the names of all courses which have been taught in 南疆雨林 ever. (there should be no duplicate names)
mysql> select distinct title-> from course, section-> where course.course_id=section.course_id and building='南疆雨林';
+----------+
| title    |
+----------+
| 枪法     |
| 内功基础 |
| 坑蒙拐骗 |
+----------+
3 rows in set
  • Display the IDs and names of all students who have never registered for a course.
mysql> select id, name-> from student-> where tot_cred=0;
+-------+------+
| id    | name |
+-------+------+
| 70557 | 杨康 |
+-------+------+
1 row in set
  • Find the id and names of the courses which have been registered by some students without evaluated grade.
mysql> select course.course_id, title, grade-> from course, takes-> where course.course_id=takes.course_id and grade is null;
+-----------+-------+-------+
| course_id | title | grade |
+-----------+-------+-------+
| cq2       | 散打  | NULL  |
+-----------+-------+-------+
1 row in set
  • Find the courses which are the Subsequence courses of other courses. The result should involve the ids and titles of the Subsequence courses and the ids and titles of its prerequisites. (note: the names of columns in result should show the roles of the courses clearly)
mysql> select a.course_id, a.title SUB, b.course_id, b.title PRE-> from course a, course b, prereq-> where a.course_id=prereq.course_id and b.course_id=prereq.prereq_id;
+-----------+----------+-----------+----------+
| course_id | SUB      | course_id | PRE      |
+-----------+----------+-----------+----------+
| cn2       | 九阴真经 | cn1       | 内功基础 |
| cn3       | 九阳神功 | cn1       | 内功基础 |
| cn4       | 易筋经   | cn1       | 内功基础 |
| cn5       | 太极     | cn1       | 内功基础 |
| cq2       | 散打     | cq1       | 少林长拳 |
| cq3       | 自由搏击 | cq1       | 少林长拳 |
+-----------+----------+-----------+----------+
6 rows in set

大连理工大学软件学院·数据库实验相关推荐

  1. 太原理工大学软件学院数据库实验四(2021.4.26)

    太原理工大学软件学院数据库实验四(2021.4.26) -- (1)创建Student 表 CREATE TABLE Student ( Sno CHAR(8) PRIMARY KEY, Sname ...

  2. 太原理工大学软件学院 数据库实验 实验二(2021.4.8)

    太原理工大学软件学院 数据库实验 实验二(2021.4.8) 实验内容 以下内容直接全部复制到console窗口即可 需要逐句运行 -- (1)创建Student表 CREATE TABLE Stud ...

  3. 2017-2018学年大连理工大学软件学院数据库考试题目说明

    20分 10个选择(比较简单,复习注意概念,比如DBS,DB,DBMS都是什么.其中有两个有关事务的题,即第十二章内容,分别是ACID的四个性质内容和结束事务并回滚的语句是什么问题) 50分 4个关系 ...

  4. 大连理工大学软件学院编译技术课程——MicroC词法分析上机实验

    大连理工大学软件学院编译技术课程--MicroC词法分析上机实验 题目 编写词法分析编译程序 实验目的:对循环语句和条件判断语句编写词法分析编译程序,只能通过一遍扫描完成. 实验要求: (1) 关键字 ...

  5. 大连理工计算机组成实验,大连理工大学软件学院计算机组成原理实验报告

    <大连理工大学软件学院计算机组成原理实验报告>由会员分享,可在线阅读,更多相关<大连理工大学软件学院计算机组成原理实验报告(57页珍藏版)>请在人人文库网上搜索. 1.大连理工 ...

  6. 大连理工大学c语言第三次上机作业答案,大连理工大学软件学院C语言上机第五六章课后题...

    大连理工大学软件学院C语言上机第五六章课后题 五.1. #includeint main() { int a,b,c; float X,Y,Z; scanf("%d%d%d",&a ...

  7. 【20保研】大连理工大学软件学院2019年优秀大学生学术夏令营通知

    点击文末的阅读原文或者公众号界面左下角的保研夏令营或者公众号回复"夏令营"是计算机/软件等专业的所有保研夏令营信息集合,会一直更新的. 一.院系与学科介绍  大连理工大学软件工程学 ...

  8. 大连理工大学计算机考研调剂,2020年大连理工大学软件学院考研调剂公告

    考研调剂公告各院校已经发布出来了,下面由出国留学网小编为你精心准备了"2020年大连理工大学软件学院考研调剂公告",持续关注本站将可以持续获取更多的考试资讯! 2020年大连理工大 ...

  9. 大连理工大学软件学院博客地址

    大连理工大学软件学院CSDN高校俱乐部博客地址: http://blog.csdn.net/u010455967 转载于:https://www.cnblogs.com/FlightButterfly ...

最新文章

  1. 【廖雪峰python入门笔记】list_替换元素
  2. 编写里Linux命令解释器,linux基础教程试卷及答案
  3. CentOS 6.5 安装 Mysql 5.7.* (tar.gz)
  4. 简单网络管理协议(SNMP)实现linux系统信息网络监控
  5. JavaScript实现多项式哈希算法(附完整源码)
  6. Codevs 1010 过河卒 2002年NOIP全国联赛普及组
  7. 机器学习 建立模型_建立生产的机器学习系统
  8. mysql复制状态是什么意思_mysql8 参考手册--复制从SQL线程状态
  9. 安装mysql需要配置什么软件_软件配置篇-MySQL下载及安装
  10. Python的安装部署
  11. 使用JavaWeb将文件上传到后台服务器
  12. [转载] Python字典按照keys排序输出为列表
  13. java实现文件压缩打包(zip打包)(文件相关二)
  14. tp link无线路由器怎么设置
  15. 2008中国成都国际软件设计大赛“优秀选手”名单
  16. IAR使用方法建立工程文件超详细操作步骤
  17. 微信 php 地图定位,微信公众号定位地图位置写入数据库,再显示地图的方法
  18. 这款小程序 能让你和孙悟空一样 可以七十二变
  19. 单反相机滤镜种类和作用
  20. 神州数码易拓TIPTOP EPR维护作业模板-上单身下单头维护作业

热门文章

  1. UITableView_5-团购简单实现,nib封装实现,模型封装实现
  2. 图形界面介绍Set Preference—Design
  3. bland c++_为什么要使用bland altman图进行ab测试python代码
  4. ChatGPT之父Sam Altman:成功的13个关键要素
  5. mysql 建立省份表 和对应的地级市表
  6. 微信支付接口参数规定
  7. JSP养老院管理系统JSP养老院系统javaweb养老院系统JSP敬老院管理系统JSP敬老院系统
  8. spyder cv2 打开图片_谷歌百度以图搜图如何实现?教你打造属于自己的相似图片搜索引擎
  9. Python献血案例
  10. Spring | 三分钟带你了解什么是Spring