Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction: This assignment will use a database containing data about a university. You need to create all the tables/relations from the .txt files as attached.

image text in transcribed

image text in transcribed

Introduction: This assignment will use a database containing data about a university. You need to create all the tables/relations from the .txt files as attached. (You can use the psql command 'Icopy' to load the text data into database. NOTE: Remove the first schema line from the data file before using \copy. You can find an example in the attached slides.) The schema of the database is provided below (keys are in bold and underlined, field types are omitted): - student(sid, sname, sex, age, year, gpa) - dept( dname, numphds) - prof(pname, dname) - course(cno, cname, dname) - major(dname, sid) - section(dname, cno, sectno, pname) - enroll(sid, grade, dname, cno, sectno) Note: Some students have not declared a major, and your queries need to take that into consideration and accommodate it accordingly. A. Queries (Student Database) Write SQL queries that answer the questions below (one query per question). The query answers must not contain duplicates, but you should use the SQL keyword distinct ONLY when necessary. Submit both the queries (text form) and the screen shot of the execution of each query including the returned results. Your queries will be graded based on both the correctness and the succinctness. If your query does not compile at all, no point will be awarded. Questions 1. For each Computer Sciences class, print the cno, sectno, and the average gpa of the students enrolled in the class. (6 pts) 2. Print the course names, course numbers and section numbers of all classes with less than six students enrolled in them. (8 pts) 3. Print the names of departments that have one or more majors who are under 18 years old. (8 pts) 4. Print the names and majors of students who are taking one of the College Geometry courses. For students who do not have a major, print out some special string, e.g., an empty string, as his/her major. (Hint:You'll need to use the "like" predicate and the string matching character in your query. You also likely need to use SET operations.) (12 pts) 5. For those departments that have no majors taking a College Geometry course, print the department name and the number of PhD students in the department. (12 pts) 6. Print the names of students who are taking both a Computer Sciences course and a Mathematics course. (12 pts) 7. Print the age difference between the oldest and youngest Computer Sciences major(s). (10 pts) 8. For each department that has one or more majors with a GPA under 1.0, print the name of the department and the average GPA of its majors. (15 pts) 9. Print the ids, names, and GPAs of the students who are currently taking all of the Civil Engineering courses. (15 pts) B. More SQL Queries (Product Database) Write the following queries, based on the database schema: Product(maker, model, type) PC(model, speed, ram, hd, price) Laptop(model, speed, ram, hd, screen, price) Printer(model, color, type, price) The Product relation gives the manufacturer, model number and type ( PC, laptop, or printer) of various products. We assume for convenience that model numbers are unique over all manufacturers and product types. The PC relation gives for each model number that is a PC the speed(in Ghz), the amount of ram (in MB), the size of the hard disk (in GB), and the price. The Laptop relation is similar, except that the screen size (in inches) is also included. The Printer relation records for each printer model whether the printer produces color output (true if so), the process type (laser or ink-jet, typically), and the price. (a) (7 points) Find the average price of PC's and laptops made by manufacturer "D." (b) (8 points) Find the average hard disk size of a PC for all those manufacturers that make printers. NOTE: You need to create your own test tables and output the results. Submit both the queries (text form) and the screen shot of the execution of each query including the returned results. Your queries will be graded based on both the correctness and the succinctness. Assignment Submission This is an individual assignment - no group submissions are allowed. Submit to Canvas: 1. Your SQL statements and query results. (screenshots showing your PostgreSQL login with your DB Web user name, the SQL statement issued, and the results returned.) 2. Your DB name, web username, and web user password

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago