MIS SQL Assignment 29-044 Gourab Mondal
MIS SQL Assignment 29-044 Gourab Mondal
WRITING SQL
QUERIES
W202
Assignment on
Writing SQL Queries
Submitted to
Md. Mahmudur Rahman
Assistant Professor,
Department of Computer Science & Engineering, University of Dhaka
Submitted by
Gourab Mondal,
Date of Submission
FROM student
2. Find the name(s) of the departments where some student named 'Jack' has
been registered.
SELECT DISTINCT dept_name
FROM student
WHERE name='Jack';
1|Page
3. Find all the departments situated in 'Packard' building or 'Watson'
building. SELECT dept_name
FROM department
WHERE building IN ('Packard', 'Watson');
4. Find the name(s) of the instructors who get more than 50000 salary.
SELECT name
FROM instructor
WHERE salary > 50000;
2|Page
5. Find the classroom(s) (building with room number) with a capacity of at
least 20 but no more than 50.
SELECT building, room_number
FROM classroom
WHERE capacity >= 20 AND capacity <= 50;
3|Page
8. Show the department names with budgets where the budget is less than
20000.
SELECT dept_name
FROM department
WHERE budget < 20000;
4|Page
10. Find the names of the student(s) who are advised by some instructor(s)
with more than 50000 salary. SELECT student.name
FROM student
INNER JOIN advisor ON student.ID = advisor.s_ID
INNER JOIN instructor ON advisor.i_ID = instructor.ID
WHERE instructor.salary > 50000;
11. Show a list of courses taught by some instructors from Physics department
in Spring 2008.
SELECT course.title
FROM course
JOIN section ON course.course_id = section.course_id
JOIN teaches ON teaches.course_id = section.course_id
AND teaches.sec_id = section.sec_id
AND teaches.semester = 'Spring'
AND teaches.year = 2008
JOIN instructor ON teaches.ID=instructor.ID
WHERE instructor.dept_name = 'Physics';
5|Page
12. List a pair of courses where the courses of a pair have equal credits. [Pair
should contain different courses]
SELECT c1.title AS course1, c2.title AS course2
FROM course c1
INNER JOIN course c2 ON c1.course_id <> c2.course_id AND c1.credits = c2.credits;
6|Page
13. Show a list of student and instructor pairs where the student of a pair has taken a
course of the instructor and achived a grade 'A'.
SELECT DISTINCT s.name AS student_name, i.name AS instructor_name
FROM student s
JOIN takes t ON s.ID = t.ID
JOIN teaches tch ON t.course_id = tch.course_id AND t.sec_id = tch.sec_id AND t.semester =
tch.semester AND t.year = tch.year
JOIN instructor i ON tch.ID = i.ID
WHERE t.grade = 'A';
14. Find the instructors who have never taken any courses.
SELECT instructor.name
FROM instructor
LEFT JOIN teaches
ON instructor.ID=teaches.ID
WHERE teaches.ID is null;
7|Page
15. Suppose there is a scheme that each department will get some
compensation on budget. Condition is, department will get 20% compensation
if the number of instructor is less than 5. Otherwise, it will get 15% as
compensation. Show a list of department with the compensation amount.
output: (Name of the department, Amount of compensation)
SELECT dept_name,
CASE WHEN (SELECT COUNT(*) FROM instructor WHERE dept_name = d.dept_name)
<5
THEN budget * 0.2
ELSE budget * 0.15
END AS compensation
FROM department d;
8|Page
16. Show the classrooms that were never utilized for any classes.
9|Page