IT Learning HubIT Learning Hub
WEEK 4 · PRACTICE EXERCISES

Exercises & Answer Key

IT004BTTH4Academic Affairs Management

The exercise statement is open to read freely. The answer key and detailed explanations are reserved for students currently enrolled in the IT004 practicum class and require an access code from the instructor.

EXERCISE · PARTS I-III

Academic Affairs Management - Questions 1 ➜ 50

Week 4 first practices a few extended functions (CAST, GETDATE, LEFT, RIGHT), CASE WHEN, and Alias/Subquery, then applies them across 50 main questions on the Academic Affairs Management schema: Part I - Data Definition Language (questions 1-11), Part II - Data Manipulation Language (questions 1-4), Part III - Data Query Language (questions 1-35). Try it yourself before checking the answer key. Full question details are in the PDF below.

Full exercise - Week 4 practice (BTTH4) PDF file · Academic Affairs Management
Download ↓
Uses the shared Academic Affairs Management schema (HOCVIEN, LOP, KHOA, MONHOC, DIEUKIEN, GIAOVIEN, GIANGDAY, KETQUATHI) - see the full attributes, sample data, and database script. View schema ›
Submission requirement: Save your work in a single script file named <MSSV>_<HoVaTen>_BTTH4.sql (MSSV is your student ID, HoVaTen is your full name).

Part I - Data Definition Language (questions 1-11)

  1. Create the relations and declare all primary key and foreign key constraints. Add the 3 attributes GHICHU, DIEMTB, XEPLOAI to the relation HOCVIEN.
  2. The attribute GIOITINH may only hold "Nam" or "Nu".
  3. An exam score must be between 0 and 10 and needs to be stored with 2 decimal places (e.g. 6.22).
  4. The exam result is "Dat" if the score is from 5 to 10, and "Khong dat" if the score is below 5.
  5. A student may take an exam for a given subject at most 3 times.
  6. The semester value can only be from 1 to 3.
  7. A teacher's degree can only be one of "CN", "KS", "Ths", "TS", "PTS".
  8. A student must be at least 18 years old.
  9. For a course being taught, the start date (TUNGAY) must be earlier than the end date (DENNGAY).
  10. A teacher must be at least 22 years old when hired.
  11. For every subject, the theory credit count and the practice credit count may not differ by more than 3.

Part II - Data Manipulation Language (questions 1-4)

  1. Increase the salary coefficient by 0.2 for teachers who are department heads.
  2. Update the average score (DIEMTB) across all subjects for each student (every subject has weight 1, and if a student has taken an exam multiple times, only the score from the most recent attempt counts).
  3. Update the GHICHU column to "Cam thi" for the case where: a student scores below 5 on their 3rd attempt at any subject.
  4. Update the XEPLOAI column in the relation HOCVIEN as follows: "XS" if DIEMTB ≥ 9 · "G" if 8 ≤ DIEMTB < 9 · "K" if 6.5 ≤ DIEMTB < 8 · "TB" if 5 ≤ DIEMTB < 6.5 · "Y" if DIEMTB < 5.

Part III - Data Query Language (questions 1-35)

  1. Print the list (student ID, full name, date of birth, class code) of each class's class monitor.
  2. Print the exam scoresheet (student ID, full name, attempt number, score) for the CTRR subject in class "K12", sorted by student first and last name.
  3. Print the list of students (student ID, full name) and the subjects they passed on their first attempt.
  4. Print the list of students (student ID, full name) in class "K11" who failed the CTRR subject (on attempt 1).
  5. * List of students (student ID, full name) in class "K" who failed the CTRR subject (across all attempts).
  6. Find the names of the subjects taught by the teacher named "Tran Tam Thanh" in semester 1 of 2006.
  7. Find the subjects (subject code, subject name) taught by the homeroom teacher of class "K11" in semester 1 of 2006.
  8. Find the full name of the class monitor of the class(es) where the teacher named "Nguyen To Lan" teaches "Co So Du Lieu".
  9. Print the list of subjects (subject code, subject name) that must be completed as a prerequisite before "Co So Du Lieu".
  10. Which subjects (subject code, subject name) require "Cau Truc Roi Rac" as a mandatory prerequisite?
  11. Find the full name of the teacher who taught CTRR to both class "K11" and class "K12" in the same semester 1 of 2006.
  12. Find the students (student ID, full name) who failed the CSDL subject on their 1st attempt but have not yet retaken it.
  13. Find the teachers (teacher ID, full name) not assigned to teach any subject.
  14. Find the teachers (teacher ID, full name) not assigned to teach any subject belonging to the department they head.
  15. Find the full names of students in class "K11" who either failed any subject on more than 3 attempts and are still "Khong dat", or scored exactly 5 on their 2nd attempt at CTRR.
  16. Find the full name of the teacher who taught CTRR to at least 2 classes in the same semester of the same academic year.
  17. List of students and their CSDL exam scores (using only the score from the most recent attempt).
  18. List of students and their "Co So Du Lieu" exam scores (using the highest score across all attempts).
  19. Which department (department code, department name) was established earliest?
  20. How many teachers hold the academic rank "GS" or "PGS"?
  21. Report how many teachers hold the degree "CN", "KS", "Ths", "TS", "PTS" within each department.
  22. For each subject, report the number of students by result (passed and failed).
  23. Find the teachers (teacher ID, full name) who are the homeroom teacher of a class and also teach at least one subject to that same class.
  24. Find the full name of the class monitor of the class with the largest enrollment.
  25. * Find the full names of class monitors (LOPTRG) who failed more than 3 subjects (each subject failed on every attempt).
  26. Find the student (student ID, full name) with the most subjects scored 9 or 10.
  27. Within each class, find the student (student ID, full name) with the most subjects scored 9 or 10.
  28. For each semester of each academic year, report how many subjects and how many classes each teacher was assigned to teach.
  29. For each semester of each academic year, find the teacher (teacher ID, full name) who taught the most.
  30. Find the subject (subject code, subject name) with the highest number of students who failed (on the 1st attempt).
  31. Find students (student ID, full name) who passed every subject they took (considering only the 1st attempt).
  32. * Find students (student ID, full name) who passed every subject they took (considering only the most recent attempt).
  33. * Find students (student ID, full name) who passed all subjects taken (considering only the 1st attempt).
  34. * Find students (student ID, full name) who passed all subjects taken (considering only the most recent attempt).
  35. ** Find the student (student ID, full name) with the highest score in each subject (using the most recent attempt's score).

ANSWER

View answer

Protected content

Enter the access code to view the Week 4 answer.

Access code provided by the instructor.