Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can.

Similar presentations


Presentation on theme: "Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can."— Presentation transcript:

1 Exam #2 Review with Answers

2  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can NOT use other people, email, phone a friend, text a friend, etc.  When you complete all of the questions, zip up the SQL and submit through Angel  Drop Box for Exam #2  When you are finished, please verify that I have received your file BEFORE you leave class  You will have the entire 1 hour and 15 minutes to complete the exam

3  Select statements  Select clause  From clause  Where clause  Group by clause  Having clause  Order by clause

4  Additional topics  Equijoins  Subqueries  Row functions  Aggregate functions  And, or, not logic  Dates  Number and character functions

5  Using the Student table  How many students are in this table?  List the first and last names of the students using this format: lastname, firstname ▪ Notice the space between the comma and firstname  List the area code of the phone number  List all unique registration dates  List the number of students that registered on each registration date

6  Using the appropriate table(s)  How many cities per state are there currently listed in our database? ▪ List in alphabetical order  List the states that have at least 60 unique cities currently listed in our database ▪ List in alphabetical order  (1) List all sections that have a start date time of May 4, 2007  (2) List all sections that have a modified date of Jan 2, 2007  Explain the following difference between query (1) and (2) by writing the appropriate query ▪ To find the start date time of May 4, 2007 you needed to use the trunc function ▪ Why did the start date time search require the trunc function? ▪ To find the modified date of Jan 2, 2007 you did not need to use trunc ▪ Why did the modified date search not require the trunc function?

7  Using the appropriate table(s)  List the first name, last name and section id for all students actually enrolled in a section  List how many classes each student is currently taking

8 -- How many students are in this table? SELECT count(*) FROM student.student; -- List the first and last names of the students using this format: lastname, firstname SELECT last_name || ', ' || first_name from student.student; -- List the area code of the phone number SELECT phone, substr(phone, 1, 3) as AreaCode from student.student; -- List all unique registration dates SELECT DISTINCT(registration_date) FROM student.student;

9 -- List the number of students that registered on each registration date SELECT registration_date, count(*) FROM student.student group by registration_date; -- How many unique cities per state are there currently listed in our database? -- List in alphabetical order. SELECT state, count(distinct city) FROM student.zipcode GROUP BY state ORDER BY state; -- List the states that have at least 60 unique cities currently listed in our database. -- List in alphabetical order. SELECT state, count(distinct city) FROM student.zipcode GROUP BY state Having count(distinct city) > 59 ORDER BY state;

10 -- List all sections that have a start date of May 4, 2007 -- Using format shows that this field contains a 09:30:00 value for time SELECT section_id, to_char(start_date_time, 'DD-MON-YYYY HH24:MI:SS') FROM student.section WHERE trunc(start_date_time) = '04-May-07'; -- List all sections that have a modified date of Jan 2, 2007 -- Using format shows that this field contains a 00:00:00 value for time SELECT to_char(modified_date, 'DD-MON-YYYY HH24:MI:SS') FROM student.section WHERE modified_date = '02-Jan-07';

11 -- Explain the following difference between query (1) and (2) by writing the appropriate query -- To find the start date time of May 4, 2007 you needed to use the trunc function -- Why did the start date time search require the trunc function? -- To find the modified date of Jan 2, 2007 you did not need to use trunc -- Why did the modified date search not require the trunc function? -- ANSWER: The start_date_time column was loaded with a time other than 00:00:00 -- The modified_date was loaded without a time, in other words, 00:00:00 -- So when you search on modified date without the trunc function it looked for a 00:00:00 -- time and found it. The start_date_time value did not have a 00:00:00 value so you -- needed to use the trunc function to eliminate the time value from the where clause -- search. -- List the first name, last name and section id for all students actually enrolled in a section SELECT s.first_name, s.last_name, e.section_id FROM student.student s, student.enrollment e where s.student_id = e.student_id;

12 -- List how many classes each student is currently taking SELECT e.student_id, s.first_name, s.last_name, count(e.section_id) FROM student.student s, student.enrollment e where s.student_id = e.student_id GROUP BY e.student_id, s.first_name, s.last_name order by e.student_id;

13  Exam #2  If you do not attend class, You must contact me immediately ▪ This test is entirely computer-based ▪ Thus it will NOT be placed in the Test Center ▪ This is your responsibility! ▪ You will have until 12:00 p.m. (noon) on Friday, November 1 st to complete the exam ▪ If you do not complete the exam, you will earn 0 points for this exam score


Download ppt "Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can."

Similar presentations


Ads by Google