日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

大连理工大学软件学院·数据库实验

發布時間:2024/1/1 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 大连理工大学软件学院·数据库实验 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 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

總結

以上是生活随笔為你收集整理的大连理工大学软件学院·数据库实验的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。