0% found this document useful (0 votes)
0 views

SQL Query Exercises.doc

The document contains SQL query exercises based on a university schema, including tasks such as retrieving course titles, student IDs, instructor salaries, and enrollment figures. It also includes operations for calculating grade points and averages, as well as performing inserts, deletes, and updates. Additionally, it outlines how to assign grades based on student scores from a marks relation.

Uploaded by

jtijerina8208
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

SQL Query Exercises.doc

The document contains SQL query exercises based on a university schema, including tasks such as retrieving course titles, student IDs, instructor salaries, and enrollment figures. It also includes operations for calculating grade points and averages, as well as performing inserts, deletes, and updates. Additionally, it outlines how to assign grades based on student scores from a marks relation.

Uploaded by

jtijerina8208
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL Query Exercises

1. Write the following queries in SQL, using the university schema.


a. Find the titles of courses in the Compu.Sci. Department that have 3 credit hours.
SELECT title
FROM course
WHERE depart_name = ‘Comp. Sci.’
AND credits = 3

b. Find the IDs of all students who were taught by an instructor named Einstein; make sure
there are no duplicates in the result.
SELECT DISTINCT student.ID
From (student join takes using(ID))
using(course_id, sec_id, semester, year)
WHERE instructor.name = ‘Einstein’

c. Find the highest salary of any instructor.


SELECT MAX salary
FROM instructor

d. Find all instructors earning the highest salary.


SELECT name
FROM instructors
WHERE salary = (select max(salary) from instructor

e. Find the enrollment of each section that was offered in the Fall 2009.

f. Find the maximum enrollment, across all sections, in Fall 2009.

g. Find the sections that had the maximum enrollment in Fall 2009.

2. Suppose you are given a relation grad_poins(grade, points) which provides a conversion from letter
grades in the takes relation to numeric score; for example an “A” grade could be specified to correspond
to 4 points , and “A-” to 3.7 points, a “ B+” to 3.3 points, a “B” to 3 points, and so on. The grades earned
by a student for a course offering (section) is defined as the number of credits for the course multiplied
by the numeric points for the grade that the student received.

Give the above relation, and our university schema, write each of the following queries in SQL. You can
assume for simplicity that no takes tuple has null value for grade.
a. Find the total grade-points earned by the student with ID 12345, across all course taken by the
student.
b. Find the grade-point average (GPA) for the above student, that is, the total grade-points divided
by the total credits for the associated courses.
c. Find the ID and the grade-point average of every student.
3. Write the following inserts, deletes or updates in SQL, using the university schema.
a. Increase the salary of each instructor in the Comp.Sci. department by 10%.
b. Delete all courses that have never been offered. (that is, do not occur in the section relation)
c. Insert every student whose tot_cred attribute is greater than 100 as an instructor in the same
department, with a salary of $10,000.

4. Suppose that we have a relation marks(ID, score) and we wish to assign grades to students based on
the score as follows: grade F i score < 40, grade C if 40<= score < 60, grade B if 60<= score< 80, and grade
A if 80<=score. Write SQL queries to do the following:
a. Display the grade for each student, based on the marks relation.
b. Find the number of students with each grade.

You might also like