CIS250 Final Exam Questions

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

CIS 250 FINAL Each question should be answered with one sql statement. Do your own work.

Do not leave any question blank, as partial credit is always given.


1)

10 pts Find the columns that make up the primary key of the instructor table. Show both the sql statement you used to get your results, and the actual column(s) that make up the key. DESCRIBE INSTRUCTOR INSTRUCTOR_ID Find all the foreign keys on the course table. Show both the sql statement you used to get your results, and the actual column(s) that make up the foreign key. Also state what the parent table is for this foreign key. SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'INSTRUCTOR' AND CONSTRAINT_TYPE = 'R' ACTUAL COLUMN(S) THAT MAKE UP THE FOREIGN KEY = ZIP THE PARENT TABLE FOR THIS FOREIGN KEY IS ZIPCODE

2) Using the course table, find all the courses that cost less than the average course price. Show description, course_no, and cost in your results. Order by cost in descending order. Make sure your cost is in $9,999 format. SELECT AVG(COST) FROM COURSE SELECT COURSE_NO, DESCRIPTION, COST FROM COURSE ORDER BY COST 3) Using the course and section tables, list all the courses and their corresponding sections. Show course_no, description, cost, start_date_time in your results. Order your results by course_no, then description. Make sure that your course_no, description, and cost do not duplicate in the display of your results. CREATE OR REPLACE VIEW CRS_SECT AS SELECT A.COURSE_NO, A.DESCRIPTION, A.COST, B.START_DATE_TIME FROM COURSE A, SECTION B SELECT * FROM COURSE_SECTION CREATE OR REPLACE VIEW CRS_SECT2 AS

SELECT DISTINCT COURSE_NO, DESCRIPTION, COST, START_DATE_TIME FROM COURSE_SECTION ORDER BY COURSE_NO, DESCRIPTION SELECT * FROM CRS_SECT2 4) Using the zipcode and instructor table, give me all the zipcodes and the count of instructors that live in those zipcodes. CREATE OR REPLACE VIEW ZIPCODE_INSTRUCTOR AS SELECT A.ZIP, B.INSTRUCTOR_ID FROM ZIPCODE A, INSTRUCTOR B WHERE A.ZIP = B.ZIP SELECT * FROM ZIPCODE_INSTRUCTOR 5) Using the zipcode and student table, find me all the students that live in Brooklyn. Show student_id, first_name, last_name, street_address, state, and zip in your results. Order your results by last_name, then first_name. CREATE VIEW VIEW_FINAL5 AS (SELECT A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, A.STREET_ADDRESS, B.STATE, B.ZIP FROM STUDENT A, ZIPCODE B WHERE A.ZIP = B.ZIP); SELECT * FROM VIEW_FINAL5 WHERE STATE = 'NY' AND ZIP BETWEEN '11029' AND '11238' ORDER BY LAST_NAME, FIRST_NAME; 6) Using the instructor and section table, list all the instructors and the number of sections they teach. Show first_name, last_name, and the number of sections they teach. Order your results by the number of sections in descending order. CREATE VIEW VIEW_FINAL6 AS (SELECT A.INSTRUCTOR_ID, A.FIRST_NAME, A.LAST_NAME, B.SECTION_ID, B.SECTION_NO FROM INSTRUCTOR A, SECTION B WHERE A.INSTRUCTOR_ID = B.INSTRUCTOR_ID); SELECT DISTINCT * FROM VIEW_FINAL6;

7) List all the students who live in the same zipcode as the instructor Tom Wojick. Show first_name, last_name, street_address and zip in your results. SELECT * FROM INSTRUCTOR; SELECT FIRST_NAME, LAST_NAME, STREET_ADDRESS, ZIP FROM STUDENT WHERE ZIP = 10025;

8) List all the students who registered before Vera Wetcel. salutation, first_name, and last_name in your results.

Show student_id,

SELECT * FROM STUDENT WHERE LAST_NAME = 'WETCEL'; SELECT STUDENT_ID, SALUTATION, FIRST_NAME, LAST_NAME FROM STUDENT WHERE REGISTRATION_DATE < '23-FEB-99' ORDER BY STUDENT_ID; 9) Using the student and enrollment table, find all the students who havent enrolled in any classes. Show student_id in your results. CREATE VIEW VIEW_FINAL9 AS (SELECT A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, B.ENROLL_DATE FROM STUDENT A, ENROLLMENT B WHERE A.STUDENT_ID = B.STUDENT_ID); SELECT STUDENT_ID FROM VIEW_FINAL9 WHERE ENROLL_DATE = NULL; 10) Create a view called all_people_view that lists all the students and instructors currently present at the university. Show salutation, full_name, street_address, zip, phone in your results. The full_name column should be the first_name last_name columns from the tables. CREATE VIEW ALL_PEOPLE_VIEW AS (SELECT SALUTATION, LAST_NAME, FIRST_NAME, STREET_ADDRESS, ZIP, PHONE FROM STUDENT UNION SELECT SALUTATION, LAST_NAME, FIRST_NAME, STREET_ADDRESS, ZIP, PHONE FROM INSTRUCTOR); SELECT SALUTATION, FIRST_NAME || ' ' || LAST_NAME AS FULL_NAME, STREET_ADDRESS, ZIP, PHONE FROM ALL_PEOPLE_VIEW; 11) Create a view called all_students_view that lists the student_id, salutation, first_name, last_name CREATE VIEW ALL_STUDENTS_VIEW AS (SELECT STUDENT_ID, SALUTATION, FIRST_NAME, LAST_NAME FROM STUDENT); SELECT * FROM ALL_STUDENTS_VIEW;

12) From the enrollment and student tables, show the student who got the highest grade. Show first_name, last_name, and student_id in your results. SELECT DISTINCT A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, MAX(NVL(B.FINAL_GRADE, 0)) AS FINAL_GRADE FROM STUDENT A, ENROLLMENT B WHERE A.STUDENT_ID = B.STUDENT_ID GROUP BY A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, B.FINAL_GRADE ORDER BY STUDENT_ID; 13) Using the course, section tables, list all the courses who have more than 5 sections. Show course_no, description, and number of sections. SELECT DISTINCT A.COURSE_NO, A.DESCRIPTION, B.SECTION_NO FROM COURSE A, SECTION B WHERE A.COURSE_NO = B.COURSE_NO AND SECTION_NO > 5 ORDER BY COURSE_NO;
14)

10pts List all the courses and their prerequisites (if any). Show course_no, description, cost of the course, and course_no, description of the prerequisite. SELECT COURSE_NO, DESCRIPTION, COST, PREREQUISITE FROM COURSE ORDER BY COURSE_NO;

15)

10 pts List the course(s) who have the most sections. Show course_no, description, and number of sections in your answer. SELECT DISTINCT A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, MAX(NVL(B.FINAL_GRADE, 0)) AS FINAL_GRADE FROM STUDENT A, ENROLLMENT B WHERE A.STUDENT_ID = B.STUDENT_ID GROUP BY A.STUDENT_ID, A.FIRST_NAME, A.LAST_NAME, B.FINAL_GRADE ORDER BY STUDENT_ID;

16)

10pts Using the course, section, and enrollment tables list all the courses who have more students enrolled than their capacity allows. Show course_no,

description, start_date_time, capacity, and current number of enrolled students in your results.

CREATE VIEW HATE_THIS_CRAP AS (SELECT A.COURSE_NO, A.DESCRIPTION, B.SECTION_ID, B.START_DATE_TIME, B.CAPACITY, C.STUDENT_ID FROM COURSE A, SECTION B, ENROLLMENT C WHERE A.COURSE_NO = B.COURSE_NO AND B.SECTION_ID = C.SECTION_ID); SELECT DISTINCT DESCRIPTION, START_DATE_TIME, CAPACITY, COUNT(COURSE_NO) FROM VIEW HATE_THIS_CRAP WHERE COURSE_NO > CAPACITY GROUP BY DESCRIPTION, START_DATE_TIME, CAPACITY, COURSE_NO;

You might also like