Find the number of students with each grade.

Basic sql question

Question 1 (Textbook Chapter 3: Practice 3.2)

3.2 Suppose you are given a relation grade_points(grade, points) that provides a con-version from letter grades in the takes relation to numeric scores; for example, an “A” grade could be specified to correspond to 4 points, an “A—” to 3.7 points, a “B+” to 3.3 points, a “B” to 3 points, and so on. The grade points 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. Given the preceding relation, and our university schema, write each of the following queries in SQL. You may assume for simplicity that no takes tuple has the null value for grade.

  • a. Find the total grade points earned by the student with ID ‘12345’, across all courses 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 each student.
  • d. Now reconsider your answers to the earlier parts of this exercise under the assumption that some grades might be null. Explain whether your solutions still work and, if not, provide versions that handle nulls properly.

Question 2 (Textbook Chapter 3: Practice 3.5)

3.5 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 if 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.

Question 3: (Textbook Chapter 3: Practice 3.8)

branch(branchjzame, branch.city, assets) customer (ID, customer_name, customer_street, customer.city) loan (loan number, branch_name, amount) borrower (ID, loan_number) account (account_number, branch_name, balance ) depositor (ID, account_number)

Figure 3.18 Banking database.

3.8 Consider the bank database of Figure 3.18, where the primary keys are under-lined. Construct the following SQL queries for this relational database.

  • a. Find the ID of each customer of the bank who has an account but not a loan.
  • b. Find the ID of each customer who lives on the same street and in the same city as customer ‘12345’.
  • c. Find the name of each branch that has at least one customer who has an account in the bank and who lives in “Harrison”.

Question 4: (Textbook Chapter 6: Practice 6.2)

6.2 Consider a database that includes the entity sets student, course, and section from the university schema and that additionally records the marks that students receive in different exams of different sections.

  • a. Construct an E-R diagram that models exams as entities and uses a ternary relationship as part of the design.
  • b. Construct an alternative E-R diagram that uses only a binary relationship between student and section. Make sure that only one relationship exists between a particular student and section pair, yet you can represent the marks that a student gets in different exams.