Skip to main content

Posts

Showing posts from June, 2009

Question 9: null in where clause

The EMP table contains these columns: LAST NAME VARCHAR2(25) SALARY NUMBER(6,2) DEPARTMENT_ID NUMBER(6) You need to display the employees who have not been assigned to any department. You write the SELECT statement: SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement? A. The SQL statement displays the desired results. B. The column in the WHERE clause should be changed to display the desired results. C. The operator in the WHERE clause should be changed to display the desired results. D. The WHERE clause should be changed to use an outer join to display the desired results. Answer: C Explanation: The operator in the WHERE clause should be changed to display the desired results. There are times when you want to substitute a value in place of NULL. Oracle provides this functionality with a special function, called NVL(). You can use operation equal with the keywords IS NULL, or you can achieve desired results using NVL() fu...

Question 8: Aggregate Functions

Examine the description of the STUDENTS table: STD_ID NUMBER(4) COURSE_ID VARCHARD2(10) START_DATE DATE END_DATE DATE Which two aggregate functions are valid on the START_DATE column? (Choose two) A. SUM(start_date) B. AVG(start_date) C. COUNT(start_date) D. AVG(start_date, end_date) E. MIN(start_date) F. MAXIMUM(start_date) Answer: C & E Explanation: It is possible to apply COUNT() and MIN() functions on the column with DATE data type. Incorrect Answers A: Function SUM() cannot be used with DATE data type column. B: Function AVG() cannot be used with DATE data type column. D: Function AVG() cannot be used with DATE data type column, and function AVG() just has one parameter X, not two. It averages all X column values returned by the SELECT statement. F: There is no MAXIMUM() function in Oracle, only MAX() function exists.

Question 7: Group By

Examine the description of the EMPLOYEES table: EMP_ID NUMBER(4) NOT NULL LAST_NAME VARCHAR2(30) NOT NULL FIRST_NAME VARCHAR2(30) DEPT_ID NUMBER(2) JOB_CAT VARCHARD2(30) SALARY NUMBER(8,2) Which statement shows the maximum salary paid in each job category of each department? A.SELECT dept_id, job_cat, MAX(salary) FROM employees WHERE salary > MAX(salary); B.SELECT dept_id, job_cat, MAX(salary) FROM employees GROUP BY dept_id, job_cat; C. SELECT dept_id, job_cat, MAX(salary) FROM employees; D. SELECT dept_id, job_cat, MAX(salary) FROM employees GROUP BY dept_id; Answer: B Explanation: This answer provides correct syntax and semantics to show the maximum salary paid in each job category of each department. Incorrect Answers A: This query will not return any row because condition SALARY > MAX(SALARY) is FALSE. C: This query will return error because you cannot show maximum salary with DEPT_ID and JOB_CAT without grouping by these columns. D: The GROUP BY clause is missing JOB_ID col...

Question 6: ORDER BY with NULL

You are sorting data in a table in you SELECT statement in descending order. The column you are sorting on contains NULL records, where will the NULL record appears? A.At the beginning of the list. B.At the end of the list. C.In the middle of the list. D.At the same location they are listed in the unordered table. Answer: A Explanation: When sorting a column with null values in ascending order then the oracle places the Null values at the end of the list if the sorting is in descending order the oracle places the null values at the start of the list.

Question 5: Where and having clauses

Which two statements are true about WHERE and HAVING clauses? (Choose two) A. A WHERE clause can be used to restrict both rows and groups. B. A WHERE clause can be used to restrict rows only. C. A HAVING clause can be used to restrict both rows and groups. D. A HAVING clause can be used to restrict groups only. Answer: B, C Explanation : HAVING clause to specify which groups are to be displayed and thus further restrict the groups on the basis of aggregate information. The Oracle server performs the following steps when youuse the Having clause 1. rows are grouped 2. the group function is applied to the group 3. the group that match the criteria in the Having clause are displayed. WHERE clause cannot be use to restrict groups HAVING clause use to restrict groups WHERE clause cannot be use when there is group functions. Incorrect Answers : A. Where clause cannot be use to restrict groups D. When HAVING clause is use rows are grouped as well.

Question: 4 - WHERE clause

The ORDERS table has these columns: ORDER_ID NUMBER(4) NOT NULL CUSTOMER_ID NUMBER(12) NOT NULL ORDER_TOTAL NUMBER(10,2) The ORDERS table tracks the Order number, the order total, and the customer to whom the Order belongs. Which two statements retrieve orders with an inclusive total that ranges between 100.00 and 2000.00 dollars? A.SELECT customer_id, order_id, order_total FROM orders RANGE ON order_total (100 AND 2000) INCLUSIVE; B.SELECT customer_id, order_id, order_total FROM orders HAVING order_total BETWEEN 100 and 2000; C. SELECT customer_id, order_id, order_total FROM orders WHERE order_total BETWEEN 100 and 2000; D. SELECT customer_id, order_id, order_total FROM orders WHERE order_total >= 100 and Answer:C Explanation: Answers C provides correct results to show. You can use BETWEEN or comparison operations to retrieve data. Incorrect Answers A: There is no RANGE ON or INCLUSIVE keyword in Oracle. B: HAVING clause can be use only in conjunction with the GROUP BY clause. D: ...
The ORDERS table has these columns: ORDER_ID NUMBER(4) NOT NULL CUSTOMER_ID NUMBER(12) NOT NULL ORDER_TOTAL NUMBER(10,2) The ORDERS table tracks the Order number, the order total, and the customer to whom the Order belongs. Which two statements retrieve orders with an inclusive total that ranges between 100.00 and 2000.00 dollars? A.SELECT customer_id, order_id, order_total FROM orders RANGE ON order_total (100 AND 2000) INCLUSIVE; B.SELECT customer_id, order_id, order_total FROM orders HAVING order_total BETWEEN 100 and 2000; C. SELECT customer_id, order_id, order_total FROM orders WHERE order_total BETWEEN 100 and 2000; D. SELECT customer_id, order_id, order_total FROM orders WHERE order_total >= 100 and Answer:C Explanation: Answers C provides correct results to show. You can use BETWEEN or comparison operations to retrieve data. Incorrect Answers A: There is no RANGE ON or INCLUSIVE keyword in Oracle. B: HAVING clause ...

Order By clause

The STUDENT_GRADES table has these columns: STUDENT_ID NUMBER(12) SEMESTER_END DATE GPA NUMBER(4,3) The registrar has requested a report listing the students grade point averages (GPA), sorted from highest grade point average to lowest within each semester, starting from the earliest date. Which statement accomplishes this? A.SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end DESC, gpa DESC; B.SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end ASC, gpa ASC; C. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY semester_end, gpa DESC; D. SELECT student_id, semester_end, gpa FROM student_grades ORDER BY gpa DESC, semester_end DESC; Answer :C Explanation: This answer shows correct syntax and semantics to receive desired result. Incorrect Answers A: Semesters will be sorted started from the oldest date, not the earliest. B: GPA data will be sorted in ascending order, what is opposite to our task. D: Semester...
Question: 2. You want to display the titles of books that meet these criteria: 1. Purchased before January 21, 20012. Price is less then $500 or greater than $900 You want to sort the results by their data of purchase, starting with the most recently boughtbook. Which statement should you use? A. SELECT book_title FROM books WHERE price between 500 and 900 AND purchase_date ORDER BY purchase_date; B. SELECT book_titleFROM books WHERE price IN (500,900) AND purchase_date ORDER BY purchase date ASC; C. SELECT book_titleFROM books WHERE price 900 AND purchase_date ORDER BY purchase date DESC; D. SELECT book_titleFROM books WHERE (price 900) AND purchase_date ORDER BY purchase date DESC; Answer: D Explanation: This statement provides required results. Incorrect Answers: A: This query will show books with price in range $500 and $900, not less then $500 or greater than $900. B: This query will show books with prices exactly $500 or $900, not less then $500 or greaterthan $900. C: This or...
Question 1. You need to display the last names of those employees who have the letter "A" as the second character in their names. Which SQL statement displays the required results? A. SELECT last_nameFROM EMPWHERE last_name LIKE '_A%'; B. SELECT last_nameFROM EMPWHERE last name ='*A%' C. SELECT last_nameFROM EMPWHERE last name ='_A%'; D. SELECT last_nameFROM EMPWHERE last name LIKE '*A%' Answer: A Explanation: Statement in this answer will show correct results because usage of operator LIKE and format mask '_A%' extract the last names of those employees who have the letter 'A' as the second character in their names. Symbol '_' in format mask substitute exactly one symbol and cannot be NULL. Incorrect Answers B: This statement will return only names starting from symbol '*'. It cannot be used as substitution symbol. C: Usage of equity operator here is not appropriate in this case: query will look exact for fi...