Question

In: Computer Science

Consider the student-section-takes DB for an education institution: student(id, name, dept_name, tot_cred) section(course_id, sec_id, semester, year,...

Consider the student-section-takes DB for an education institution:

student(id, name, dept_name, tot_cred)

section(course_id, sec_id, semester, year, building. room_number, time_slot_id)

takes(ID, course_id, sec_id, semester, year, grade)

Give a SQL query for each of the following operations:

a. Find the buildings of sections taken by Shankar. (hint: join tables, Shankar is a student name)

b. Find all id's of students who have total credit of at least 100 or taken a course with course_id: CS-101 (hint: union)

c. Find the names of students who have not taken a course with course_id: CS-101. (hint: set difference)

d. Find the student id's of students with total credits over 80 who have not taken a course with course_id: CS-101. (hint: set difference)

Solutions

Expert Solution

Below are the SQL queries to perform the given operations.

a) Join between table section, takes and student is done. Filter is used in where clause.

SELECT s.building
FROM section AS s
INNER JOIN takes AS t
ON s.sec_id = t.sec_id
INNER JOIN student AS st
ON st.id = t.ID
WHERE st.name = "Shankar";

b) Union between two queries are done. UNION is used to combine the result of two queries.

(SELECT id
FROM student
WHERE tot_cred >= 100)
UNION
(SELECT s.id
FROM student AS s
INNER JOIN takes AS t
ON s.id = t.ID
WHERE t.course_id = 'CS-101');

c) Set difference (Minus) is done between two separate queries. This results in the difference result set of the two queries.

SELECT id
FROM student
MINUS
SELECT ID
FROM takes
WHERE course_id = 'CS-101';

d) Here also set difference is used between the two queries. WHERE clause is used in both the queries to filter the result.

SELECT id
FROM student
WHERE tot_cred > 80
MINUS
SELECT ID
FROM takes
WHERE course_id = 'CS-101';


Related Solutions

Create a view that will display the student id, name, event id, category, and score for...
Create a view that will display the student id, name, event id, category, and score for all events for students who scored a 70 or below on any test. Call this view atriskstudents. a. What code did you write for this view? Insert the snip of the contents of the view SQL code here: b. Using this view, display those students who earned a score of 65 or greater. Insert your snip here *********************************************************************************************************************************************************** *********************************************************************************************************************************************************** CREATE DATABASE Class; #-- Using...
Consider the following schema: Student(id, name) Registration(id, code) Course(code, instructor) A) Explain how we can violate...
Consider the following schema: Student(id, name) Registration(id, code) Course(code, instructor) A) Explain how we can violate the foreign key constraint from the id attribute of Registration to the Student relation.   Ans. B)Give the following queries in the relational algebra. 1)What are the names of students registered in IT244?    Ans. 2 )What are the names of students registered in both IT244 and CS141? Ans.                                 3)What are the names of students who are...
Student Structure Assignment Create a Student Structure globally consisting of student ID, name, completed credits, and...
Student Structure Assignment Create a Student Structure globally consisting of student ID, name, completed credits, and GPA. Define one student in main() and initialize the student with data. Display all of the student’s data on one line separated by tabs. Create another student in main(). Assign values to your second student (do not get input from the user). Display the second student’s data on one line separated by tabs. Create a third student in main(). Use a series of prompts...
A student takes out a loan of ​$1,900 at the beginning of each semester​ (semi-annually) for...
A student takes out a loan of ​$1,900 at the beginning of each semester​ (semi-annually) for 13 semesters to pay for college. The loan charges 7.6​% interest compounded semiannually. The student graduates after the 13 semesters and refinances the loan to a lower 6.9​% rate compounded monthly with monthly payments ​(made at the end of each​ month) for 120 months. Find the monthly payment and the total interest paid. The monthly payment is ​$_____. ​(Round to the nearest cent as​...
Student Name and ID no. _________________________________________________________ Write the journal entries in the given table for below...
Student Name and ID no. _________________________________________________________ Write the journal entries in the given table for below transactions of Clean Corporation during June 2020. 1 Provided services to customers on account for $650. 2 Purchased a building using 10 year Note Payable for $200,000. 3 Paid salaries to employees, $2,600. 4 Received payment from customers to whom service was given in transaction 1 5 Paid $400 dividends to shareholders. Answer Accounts Debit Credit 1 2 3 4 5
Change program linkedListClass to the linked list for student items (a student item contains id, name...
Change program linkedListClass to the linked list for student items (a student item contains id, name and score, where the id is used as key) and test it in the main method. You can define a student item using a class of student. given the following codes; import java.util.*; public class linkedListClass {    public Node header;    public linkedListClass()    {        header = null;    }    public final Node Search(int key)    {        Node...
Consider a student with an ID number: 13762348. The student is going to select two digits...
Consider a student with an ID number: 13762348. The student is going to select two digits at random from the digits in the ID number, one after another and without replacement. What is the probability that the sum of the two digits is less than 10, given that the first digit is an odd number?
11) Enter the following using Java. Use for loop to enter student id, student name, major...
11) Enter the following using Java. Use for loop to enter student id, student name, major and grades. Also grades should display their letter grades based on their conditions. After that display the name of students and their info, and also their letter grade After that display the sum of all grades and the average Output Example: Student ID: 0957644 Student Name: Pedro Hernandez Student Major: Business Information Systems Grades for Fall 2020: Introduction to Computer Science using Java: 85,...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT