Database Programming - Section 6 - Oracle...

72
Database Programming - Section 6 Instructor Guide

Transcript of Database Programming - Section 6 - Oracle...

Page 1: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Database Programming - Section 6 Instructor Guide

Page 2: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected
Page 3: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page i

Table of Contents

Database Programming - Section 6................................................................................................................1 Lesson 1 - GROUP BY and HAVING Clauses.............................................................................................1 What Will I Learn? ........................................................................................................................................3 Why Learn It?................................................................................................................................................4 Tell Me / Show Me........................................................................................................................................5 Try It / Solve It ..............................................................................................................................................10 Lesson 2 - Practice Exercises and Quiz .........................................................................................................14 What Will I Learn? ........................................................................................................................................16 Why Learn It?................................................................................................................................................17 Tell Me / Show Me........................................................................................................................................18 Try It / Solve It ..............................................................................................................................................19 Lesson 3 - Interviewing Skills .......................................................................................................................30 What Will I Learn? ........................................................................................................................................32 Why Learn It?................................................................................................................................................33 Tell Me / Show Me........................................................................................................................................34 Try It / Solve It ..............................................................................................................................................37 Lesson 4 - Subqueries....................................................................................................................................41 What Will I Learn? ........................................................................................................................................43 Why Learn It?................................................................................................................................................44 Tell Me / Show Me........................................................................................................................................45 Try It / Solve It ..............................................................................................................................................51 Lesson 5 - Single-Row Subqueries................................................................................................................53 What Will I Learn? ........................................................................................................................................55 Why Learn It?................................................................................................................................................56 Tell Me / Show Me........................................................................................................................................57 Try It / Solve It ..............................................................................................................................................60

Page 4: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected
Page 5: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 1

Lesson 1 - GROUP BY and HAVING Clauses

Lesson 1 - GROUP BY and HAVING Clauses

Lesson Preparation

Review Study Guide requirements with students. Have students complete the study guides as part of the Try It / Solve It portion of the content.

What to Watch For When adding aggregate functions to the SELECT clause, students will forget to include individual columns from the SELECT statement in a GROUP BY clause. Make the distinction between when to use the WHERE clause and when to use the HAVING clause. The WHERE clause is used to restrict rows; the HAVING clause is used to restrict groups returned from a GROUP BY clause.

Connections Relate group functions and the ability to perform functions on group data to other familiar instances. Ask students to write pseudo SELECT statements for each. - Show the average graduation rate of the schools in several cities. - Group students by grade and then by individual classes for that grade. - Count the number of students in the school, grouped by grade. - Select a food item by type and then by brand.

Page 6: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 2

- Find the average money collected in the lunch room, grouped by month and then by day of the week. Give pseudocode answers, such as: SELECT AVG(graduation_rate), city FROM students WHERE graduation_date >= '01-JUN-00' GROUP BY city

Page 7: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 3

What Will I Learn?

What Will I Learn?

What Will I Learn?

After reading the objectives for this lesson, ask students to look at the queries shown in the graphic. Ask them to describe the query syntax and what it is designed to return. Answer: The results set will have shoes first grouped by color and for each color shoe sizes in ascending order. Now add the HAVING clause. Ask students what role HAVING had in this query. Answer: HAVING restricted the groups returned.

Page 8: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 4

Why Learn It?

Why Learn It?

Page 9: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 5

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Begin this lesson with a question from previous material: How do you find out how many records are in the DJs on Demand EVENT table? Answer: 2 SELECT COUNT(*) id FROM d_events SELECT COUNT(shoes), color, size FROM inventory GROUP BY color, size Use the graphic to explain that the GROUP BY clause must include the shirt_color column name since shirt color is not part of an aggregate function in the SELECT clause. The shirt_color column will be used to group the number of shirts into groups by shirt color. Use the graphic to draw the relationship between the WHERE clause and the HAVING clause. The HAVING clause restricted the rows returned to only those shirts that were any color except green.

Page 10: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 6

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Discuss the SQL query with students.

Page 11: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 7

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Point out that no aliases were needed in the query because the columns used in the join have different names. Ask students to rewrite the query shown in the graphic so that it includes aliases. SELECT t.description, s.artist, s.title FROM d_songs s , d_types t WHERE s.type_code = t.code GROUP BY description, artist, title;

Page 12: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 8

Tell Me / Show Me

Tell Me / Show Me

Page 13: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 9

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

How many values will be returned by this query? Answer: One value will be returned. The query will find the average salary for each department, and then from that list, select the single largest value.

Page 14: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 10

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 1. a and d are True

Page 15: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 11

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 2. a. SELECT manager_id, AVG(salary) FROM employees GROUP BY manager_id; b. SELECT cd_number, COUNT(title) FROM d_cds WHERE cd_number < 93 GROUP BY cd_number; c. SELECT ID, MAX(ID), artist AS Artist FROM d_songs WHERE duration IN('3 min', '6 min', '10 min') GROUP by ID, artist HAVING ID < 50;

Page 16: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 12

d. SELECT loc_type, rental_fee AS Fee FROM d_venues WHERE id <100 GROUP BY loc_type, rental_fee ORDER BY 2;

Page 17: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 13

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 3. SELECT MAX(song_id) FROM d_track_listings WHERE track <= 3; 4. SELECT last_name, first_name, AVG(test1) AS "Class Average" FROM gradebook WHERE grade level =10 GROUP BY gender, last_name, first_name HAVING gender ='M'; 5 a. TRUE b. FALSE c. FALSE

Page 18: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 14

Lesson 2 - Practice Exercises and Quiz

Lesson 2 - Practice Exercises and Quiz

Lesson Preparation

Read through the review questions. Ask students if there are any outstanding questions. Complete and review the practice exercises. Assign the SQL Quiz. A passing score is 7 out of 10. Assign the True/False questions in groups of 10. Stop and review each group, being careful not to just give the answers. Discuss the concept each was designed to test. Assessment: You may want to encourage students to retake the quiz until they achieve a passing score. Or you may prefer to allow only one attempt at the quiz. Allow 20 minutes for the Quiz and 10 minutes for assessment/discussion afterward. Have students work in in pairs to review what they missed on the quiz. Based on what types of questions they missed, have each pair of students choose one question they missed or did not understand to present to the group. Use this discussion to assess student understanding.

Page 19: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 15

What to Watch For None.

Connections None.

Page 20: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 16

What Will I Learn?

What Will I Learn?

Page 21: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 17

Why Learn It?

Why Learn It?

Page 22: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 18

Tell Me / Show Me

Tell Me / Show Me

Page 23: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 19

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ___F__1. The CONCAT character function combines two or more character values into one character string. (Combines no more than two) ___T__2. The SYSDATE function returns the Oracle Server date and time. ___F__3. The RPAD character function returns a right-justified value with a string of characters replicated to fill a specified number of character positions. (RPAD will put padding on the right so content will be aligned left.) ___T__4. The ROUND number function will round 469.89 to 470 if the decimal place value is omitted. ___F__5. The SUBSTR character function returns a portion of a string beginning at the start of a string to a specified number of characters. (SUBSTR extracts a string beginning at any specified value.)

Page 24: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 20

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____T_6. DESC will order alphabetical data from Z to A. ____F_7. The column name in a SELECT statement is an example of a SELECTION. (PROJECTION) ____T_8. You cannot use a column alias in the WHERE clause. ____F_9. To specify an alias in the SELECT clause for retired employee, use 'Retired Employee.' (Aliases of more than one word require double quotes.) ____T_10. Aliases always appear in UPPERCASE, unless enclosed within proper quote marks.

Page 25: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 21

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____F_11. If any column value in an arithmetic expression is NULL, the result defaults to 0. (Null is not zero; it is undefined.) ____F_12. Null values are treated as zero when using SUM functions. (Null values are ignored.) ____F_13. In arithmetic expressions, multiply and divide are evaluated after addition and subtraction. (Multiplication and division are evaluated first.) ____T_14. By default, column headings are returned in UPPERCASE. ____T_15. SQL statements are not case-sensitive, unless indicated.

Page 26: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 22

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ___ T _16. SQL statements can be entered on one or more lines. ____F_17. SQL keywords can be abbreviated using single quotes. (No abbreviation for keywords) ____F_18. Columns are displayed in the order in which they appear in the WHERE clause. (In SELECT) ____F_19. Column aliases that are more than one word require the AS prefix. (AS is optional) ____T_20. In the SELECT clause, if an expression is not a column name or a column alias, it is a literal value.

Page 27: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 23

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____F_21. Number and date values must be enclosed in single quotes. (Numbers do not need quotes.) ____T_22. The keyword DISTINCT will affect all of the columns in the statement: SELECT DISTINCT(employee_id, department_id,department_name) ____T_23. HTML DB is a type of application. ____T_24. VARCHAR2 describes variable-length character values. ____F_25. To restrict the rows returned from a query, use the SELECT clause. (WHERE clause)

Page 28: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 24

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____T_26. The comparison operator IN is used to match any of a list of items. ____F_27. Using WHERE employee_id = NULL returns all employees where do not have an employee ID. (NULL cannot be compared using =; it is not a value.) ____T_28. BETWEEN 250 AND 350 will return 101 values. ____T_29. LIKE '_ _ e%' could return 'Fred' ____F_30. To return SA_MAN, use LIKE ' SA /_%' ESCAPE ' \ ' (SA \_%' ESCAPE ' \ ' )

Page 29: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 25

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____F_31. Logical operators are evaluated in the AND, OR, NOT order. (NOT, AND, OR) ____T_32. WHERE e.last_name LIKE 'Sm%' OR d.department_id = 60 AND d.department_name = 'IT' could return anyone from the IT department whose department ID is 60. ___T__33. The rules of precedence would evaluate an expression that contained each of the following in the order: arithmetic, concatenation, NOT, OR ___T__34. The ORDER BY clause comes last in the SELECT statement. ___T__35. In SELECT last_name, first_name, the ORDER BY clause could include department_id.

Page 30: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 26

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ___T__36. The order of execution of a SELECT statement is: FROM, WHERE, SELECT, ORDER BY ___T__37. ADD_MONTHS(hire_date, 6) will return a number. ___F__38. MONTHS BETWEEN ('05-DEC-89' , '10-JUN-93') will return 4. (MONTHS_BETWEEN) ____T_39. If April 21st is a MONDAY, then NEXT_DAY('21-APR'-03', 'FRIDAY') will return 25-APR-03. ____T_40. ROUND(SYSDATE, 'YEAR') will return 01-JAN-05 if today is August 23, 2004.

Page 31: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 27

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____T_41. All group functions ignore NULL values. ____F_42. SELECT COUNT( last_name, first_name) will return the number of last and first names in the database. (Can't count two values) ____F_43. If salary values in a column are 5000, null, 4000, 7000, using AVG(salary) will return 4000. (Null is not included: 16000/3) ___T__44. AVG(DISTINCT salary) will average only the salaries that are different from each other. ___F__45. NULLIF(salary, 4000) will return 4000 if the employee's salary is 5000. (Salary must be null.)

Page 32: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 28

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: __T___46. COALESCE(hire_date, salary, commission_pct) will return salary if the hire date is NULL. __T___47. The HAVING clause is used to restrict groups. __T___48. If a GROUP BY clause is used, any column that is in the SELECT clause that is not a group function must be listed in the GROUP BY clause. __F___49. If a query lists clauses WHERE, GROUP BY, and HAVING, no ORDER BY clause can be used. (ORDER BY if used must be last.) __F___50. If a join is needed and you want to use a WHERE clause, choose a JOIN ON or JOIN USING join. (These joins do not use the WHERE clause.)

Page 33: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 29

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: ____T_51. COUNT(DISTINCT department_id) will return the number of different department IDs. ____F_52. If a column had 4 NULL employee IDs and 250 defined IDs, COUNT will return 254. (Count would be 246. Null are not included in group functions.)

Page 34: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 30

Lesson 3 - Interviewing Skills

Lesson 3 - Interviewing Skills

Lesson Preparation

This lesson is divided into three topics: Purpose of Interviews: The objective of this topic is to present different kinds of interviews that students may encounter and how the expectations of each may differ. Interview Questions: The objective of this topic is to review and discuss different kinds of questions that students might expect in an interview and to begin thinking about how to prepare answers for them. Impressions: This topic is designed to heighten student awareness that first impressions are important. The attitude "they'll just have to like me how I am" works with friends, but it may not work well in interview settings. Complete the content for this lesson in the following order: - Explain the Tell Me/Show Me: Purpose of Interviews and then proceed to Try It/Solve It: Purpose of Interviews Activity. - Explain the Tell Me/Show Me: Interview Questions That Can't Be Asked. Discuss as explained in the teacher instructions. - Explain and do the Try It/Solve It: Common Interview Questions Activity.

Page 35: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 31

What to Watch For Most students have had little experience with interviews. Relate your own experience or ask a local business owner or employer to speak to the class. Students could also ask their parents or guardians about their interview experiences.

Connections Relate your experiences interviewing for a teaching position or a job you had in college or high school. How did the high-school job interview differ from the interview for a teaching position? Ask a local business owner to speak to the class about his/her interview process. Reemphasize that, for most jobs, the interview is the only door into a job.

Page 36: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 32

What Will I Learn?

What Will I Learn?

What Will I Learn?

Read the objectives aloud. Briefly discuss the interview activity for this lesson.

Page 37: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 33

Why Learn It?

Why Learn It?

Page 38: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 34

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Ask the class if anyone has ever participated in an interview to get a job, apply for a scholarship, try out for a team, become a member of a club, or to attend a specific school. Ask students to share their experiences. What was the purpose of the interview? What kinds of questions were asked? Were any students surprised by what was asked in the interview? Did anyone who was interviewed wish they had been better prepared to answer the interviewer’s questions? Which questions were the most difficult to answer? Explain that interviews are used for many different purposes. Briefly explain each of the types of interviews in the list. Before going on, do the Try It/Solve It Purpose of Interviews Activity.

Page 39: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 35

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Read the "Interview Questions That Can't Be Asked" first paragraph to students. Ask students to find out when this act became law and why it was written.

Page 40: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 36

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Read aloud "Interview Questions That Can't Be Asked." Generate examples through discussion of questions that violate these laws. Ask students how they think employers find out the answers to these questions. What are the consequences of not providing truthful information on a job application or during an interview? (Possible question: The application asks if you have ever been convicted of a crime. How can the employer find out this information if the candidate has not been truthful or has not volunteered the information in the interview? Answer: Calling references given on the application, military records, fingerprint, and/or background checks)

Page 41: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 37

Try It / Solve It

Try It / Solve It

Try It / Solve It

Write three questions for each of the five types of interviews. Suggested answers: Employers interviewing potential new employees - Why are you interested in this position? - What is the most recent skill you learned? - Give me an example of how you handled a difficult situation at school or in your last job. Employers interviewing employees for promotions, work evaluations, progress on current work assignments - Describe an instance in the last six months where you motivated or built team spirit with coworkers. - How have you delegated some of your present responsibilities in order to meet the deadlines in your current position? - What certifications have you received since your last promotion? Schools or colleges interviewing students for admission - Why did you decide to run for a class office?

Page 42: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 38

- What volunteer work was the most rewarding for you and why did you decide to participate in it? - Why did you choose to attend our college? What career goals will you pursue? Scholarship committees interviewing students for financial aid - How do you plan to meet the scholastic requirements to keep receiving financial aid? - How do you think receiving financial aid will help you attain your goals? - How do you plan to meet the repayment requirements if you decide not to complete your academic studies? Clients interviewing a service-industry employee when considering whether or not to hire the company or person to do the job - Can you give me the names of your last three clients so I can get a recommendation and evaluation of your work? - Describe how you handle problems I may have with your work. - Are you bonded and insured?

Page 43: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 39

Try It / Solve It

Try It / Solve It

Try It / Solve It

Review the list of interview questions with the class. Using their printed copy of the questions, ask students to place an E next to those questions they feel would be easy to answer now. Place a D next to those questions that would be difficult for them to answer now. If students do not have a personal copy of the questions, ask them to identify and write down 10 questions that would be easy to answer now and 10 questions that would be difficult to answer. Ask for volunteers to identify a question from the list of interview questions that they considered difficult to answer at this time. Discuss as a group a plan or solution for preparing and being able to answer this question in the future. Explain that the question may require them to accomplish something in order to be able to answer it. Possible difficult question: "How do you define success?" What may be required to answer this question: If you don’t have prior work experience, use an example from school, your volunteer work, or your family. For example, “I have been working with an elderly man for the last four months, trying to help him write letters to his family. I decided to bring my laptop and have him dictate a letter. He was excited about it. We got the letter done and mailed it. His relatives responded back and now he wants me to help him continue writing.”

Page 44: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 40

Try It / Solve It

Try It / Solve It

Try It / Solve It

Ask students how important they think “first impressions" are. Would they expect to see a candidate interviewing for the school principal or headmaster position dressed in hiking shorts and tennis shoes? Discussing first impressions can be a touchy topic for teens who see adults as "out of the loop” when it comes to colored hair, pierced tongues, and tattoos. Convey the idea that the first impression can set the tone for the entire interview. The idea is to start an interview out on the right foot. After they land the job, they can follow the company style of acceptable dress policy.

Page 45: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 41

Lesson 4 - Subqueries

Lesson 4 - Subqueries

Lesson Preparation

None. What to Watch For

Check understanding of single-row subqueries, because this is essential for understanding the more complicated multiple-row subqueries.

Connections Students have used the comparison operators from the very beginning of this course. Ask them why single-row subqueries can't use other comparison operator conditions such as BETWEEN...AND, IN, LIKE, or IS NOT NULL? What does NOT IN = null return? Answer: If any of the subqueries using these operators return only one row, the subquery will execute. If more than one value is returned, an error will occur. If a null value is returned, no rows will be displayed. In this example, there is only one entry for Tuttle in the database. That is why it is selected. What if there were more than one Tuttle? SELECT first_name, last_name FROM f_staffs

Page 46: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 42

WHERE birthdate LIKE (SELECT birthdate FROM f_staffs WHERE LOWER(last_name) LIKE 'tuttle'); Answer : If more than one row is selected, an error will occur. The subquery must be modified to select one value. For example, WHERE LOWER( last_name) LIKE ‘tuttle’ and employee_id = 231;

Page 47: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 43

What Will I Learn?

What Will I Learn?

What Will I Learn?

This lesson's objectives are divided into two topics. Exploring information careers could be used as homework. - Learning how to construct and execute simple single-row subqueries Subqueries can be difficult for students. - Exploring information careers and professional organizations in the IT field Explain to students that they will have an opportunity to explore different types of information-technology jobs and to identify national and state organizations for IT professionals.

Page 48: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 44

Why Learn It?

Why Learn It?

Page 49: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 45

Tell Me / Show Me

Tell Me / Show Me

Page 50: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 46

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Explain the syntax in the graphic.

Page 51: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 47

Tell Me / Show Me

Tell Me / Show Me

Page 52: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 48

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Explain the graphic. In this lesson and in Lesson 5, we will be discussing only single-row subqueries that return one row to the outer query. Section 7 will introduce multiple-row subqueries.

Page 53: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 49

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Refer to the graphic. Ask students to find Monique Tuttle’s birth date. Ask students who was born after Monique Tuttle? Tell students that they just did a subquery! Step through the execution of the subquery. Emphasize that the single-row operators can return only one row to the outer query. Note: The sample data shown is not in the database. Ask students to respond to the two questions. "What do you think would happen if the subquery returned a null value or no rows?" Answer: If a null value is returned by the subquery (because the needed information was not in the database or had a null value for that row), the outer query takes the results of the subquery (null) and uses this result in its WHERE clause. The outer query finds no employee with birth date that is equal to null, and so returns no rows. If there was an employee with a value of null, the row would not be returned because comparison of two null values yields a null, hence the WHERE condition is not true. "If single-row subqueries can return only one row to the outer query, would adding a GROUP BY clause in the subquery make sense?" Answer: Since single-row subqueries can return only one value, there isn't anything to group.

Page 54: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 50

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Students often think of IT workers as programmers and computer technicians. Ask students to name other places where they see people working with computers -- supermarket checkout, fast-food order counter, and post-office customer counter. This lesson is divided into two parts: Part 1: Students use Internet resources to explore the variety of jobs in the IT industry and to find out what skills are required for each. Part 2: Students use Internet resources to find two professional organizations in a field they may be interested in pursuing.

Page 55: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 51

Try It / Solve It

Try It / Solve It

Try It / Solve It

Advise students to be realistic about their job search. Most large company websites have information about "employment" or "future with our company" links.

Page 56: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 52

Try It / Solve It

Try It / Solve It

Try It / Solve It

Students probably are not aware of professional organizations. Use organizations that you are familiar with as examples. Explain why people belong to professional organizations.

Page 57: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 53

Lesson 5 - Single-Row Subqueries

Lesson 5 - Single-Row Subqueries

Lesson Preparation

This lesson continues the discussion of subqueries from Section 6, Lesson 4. What to Watch For

Check for understanding of subqueries using group functions. Reinforce that when a group function appears in a SELECT clause, any columns not part of the group function must appear in a GROUP BY clause. Also, remind students that the HAVING clause is used in subqueries just as in other SELECT statements: to restrict the groups returned.

Connections The concept of predefining or selecting data occurs in everyday life without our even thinking about it. An employer screening job applications wants to find the best candidate to hire. Before being able to interview anyone, the employer must identify candidates who meet the selection basic criteria. From the list of applicants, a person who meets the basic criteria can then be selected for the interview. A way to represent this process in "pseudocode" is: SELECT new_employee FROM interview WHERE applicant =

Page 58: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 54

(SELECT applicant FROM applications WHERE degree = ‘college’ and ‘qualification' IS NOT NULL);

Page 59: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 55

What Will I Learn?

What Will I Learn?

Page 60: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 56

Why Learn It?

Why Learn It?

Why Learn It?

Ask students how many of them use Internet search engines such as http://www.google.com or http://www.yahoo.com. Relate the function of search engines in locating information to that of a subquery.

Page 61: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 57

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Review the subquery rules with students. Before going on, students should complete problems 1-4 in Try It / Solve It.

Page 62: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 58

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Explain the graphic as it relates to using two different tables to extract data in the subquery before processing the outer or main query. In the outer query, four different values are requested. However, two of the values (job_id and department_id) must meet specific conditions: the job_id must be the same as that of employee 114 and the department_id must be one at location_id 1500. Note: Not all data is displayed in the graphic. Before going on, students should complete problems 5 and 6 in Try It / Solve It.

Page 63: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 59

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Review the following group functions: MIN, MAX, AVG, COUNT, SUM. In the example shown, substitute MIN and AVG in the subquery and discuss what result would be returned. MIN: Will someone have a salary less than the minimum salary? AVG: Return the employees whose salary is less than the average salary for all employees.

Page 64: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 60

Try It / Solve It

Try It / Solve It

Page 65: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 61

Try It / Solve It

Try It / Solve It

Try It / Solve It

Review the following group functions: MIN, MAX, AVG, COUNT, SUM. In the example shown, substitute MIN and AVG in the subquery and discuss what result would be returned. MIN: Will someone have a salary less than the minimum salary? AVG: Return the employees whose salary is less than the average salary for all employees. 3. SELECT song_id FROM d_play_list_items WHERE event_id= (SELECT event_id FROM d_play_list_items WHERE song_id = 45);

Page 66: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 62

4. SELECT name FROM d_events WHERE cost > (SELECT cost FROM d_events WHERE id = 100);

Page 67: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 63

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 5. SELECT track, cd_number FROM d_track_listings WHERE cd_number = (SELECT cd_number FROM d_cds WHERE title LIKE 'Party Music for All Occasions'); 6. SELECT name FROM d_events WHERE theme_code = (SELECT code FROM d_themes WHERE description = 'Tropical'); 7. SELECT last_name

Page 68: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 64

FROM f_staffs WHERE salary > (SELECT salary FROM f_staffs WHERE id = 12); 8. SELECT last_name FROM f_staffs WHERE staff_type <> (SELECT staff_type FROM f_staffs WHERE last_name = 'Miller');

Page 69: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 65

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 9. SELECT staff_type FROM f_staffs WHERE salary < (SELECT max(salary) FROM f_staffs WHERE staff_type = 'Cook'); 10. SELECT name FROM d_events WHERE theme_code = (SELECT theme_code FROM d_events WHERE id = 100); 11. SELECT first_name, last_name

Page 70: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 66

FROM employees WHERE department_id = (SELECT department_id FROM departments WHERE department_name = 'IT'); 12. SELECT department_name FROM departments WHERE location_id = (SELECT location_id FROM locations WHERE city= 'Seattle');

Page 71: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 67

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 13. SELECT department_id, min(salary) FROM employees GROUP BY department_id HAVING min (salary)> (SELECT MIN (salary) FROM employees WHERE department_id <> 50); 14. a and b are true.

Page 72: Database Programming - Section 6 - Oracle Academyacademy.oracle.com/pages/docs_pdfs_zip/2004_2005... · Database Programming - Section 6 Page 2 - Find the average money collected

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 6 Page 68