sql_test_1

25
1. The TEACHER table contains these columns: ID NUMBER(9) Primary Key LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) SUBJECT_ID NUMBER(9) Which query should you use to display only the full name of each teacher along with the identification number of the subject they are responsible for teaching? o SELECT * FROM teacher; o SELECT last_name, subject_id FROM teacher; o SELECT last_name, first_name, id FROM teacher; o SELECT last_name, first_name, subject_id FROM teacher; 2. The EMPLOYEE_HIST table contains these columns: EMPLOYEE_ID NUMBER Primary Key LAST_NAME VARCHAR2(25) FIRST_NAME VARCHAR2(25) DEPARTMENT_ID NUMBER(3) POSITION VARCHAR2(30) MANAGER_ID NUMBER SALARY NUMBER(6,2) Evaluate this statement: SELECT DISTINCT department_id, manager_id FROM employee_hist; Which statement is true? o A particular DEPARTMENT_ID can only be displayed once. o A particular MANAGER_ID can be displayed more than once.

Transcript of sql_test_1

1. The TEACHER table contains these columns:

ID NUMBER(9) Primary KeyLAST_NAME VARCHAR2(25)FIRST_NAME VARCHAR2(25)SUBJECT_ID NUMBER(9)

Which query should you use to display only the full name of each teacher along with the identification number of the subject they are responsible for teaching?

o SELECT *

FROM teacher;

o SELECT last_name, subject_id

FROM teacher;

o SELECT last_name, first_name, id

FROM teacher;

o SELECT last_name, first_name, subject_id

FROM teacher;

2. The EMPLOYEE_HIST table contains these columns:

EMPLOYEE_ID NUMBER Primary KeyLAST_NAME VARCHAR2(25)FIRST_NAME VARCHAR2(25)DEPARTMENT_ID NUMBER(3) POSITION VARCHAR2(30)MANAGER_ID NUMBER SALARY NUMBER(6,2)

Evaluate this statement:

SELECT DISTINCT department_id, manager_idFROM employee_hist;

Which statement is true?

o A particular DEPARTMENT_ID can only be displayed once.

o A particular MANAGER_ID can be displayed more than once.

o A unique combination of MANAGER_ID and DEPARTMENT_ID may displayed more

than once.

o The query will fail because the DISTINCT keyword may only be used in a single column

SELECT list.

3. The SERVICE table contains these columns:

ID NUMBER PKSERVICE_DATE DATETECHNICIAN_ID NUMBERDESCRIPTION VARCHAR2(50)

Which SELECT statement could you use to display the number of times each technician performed a service between January 1, 2001 and June 30, 2001?

o SELECT COUNT(*)

FROM serviceWHERE service_date BETWEEN '01-JAN-2001' AND '30-JUN-2001'GROUP BY service_date;

o SELECT COUNT(service_date)

FROM serviceWHERE service_date BETWEEN '01-JAN-2001' AND '30-JUN-2001'GROUP BY service_date;

o SELECT technician_id, service_date, COUNT(*)

FROM serviceWHERE service_date BETWEEN '01-JAN-2001' AND '30-JUN-2001'ORDER BY technician_id, service_date;

o SELECT technician_id, COUNT(technician_id)

FROM serviceWHERE service_date BETWEEN '01-JAN-2001' AND '30-JUN-2001'GROUP BY technician_id;

4. Evaluate this SQL statement:

SELECT manufacturer_id, COUNT(*), order_dateFROM inventoryWHERE price > 5.00GROUP BY order_date, manufacturer_idHAVING COUNT(*) > 10ORDER BY order_date DESC;

Which clause specifies which rows will be returned from the INVENTORY table?

o SELECT manufacturer_id, COUNT(*), order_date

o WHERE price > 5.00

o GROUP BY order_date, manufacturer_id

o ORDER BY order_date DESC;

o HAVING COUNT(*) > 10

5. The LINE_ITEM table contains these columns

LINE_ITEM_ID NUMBER(9) Primary KeyORDER_ID NUMBER(9) PRODUCT_ID VARCHAR2(9)QUANTITY NUMBER(5)

Evaluate this SQL statement:

SELECT quantity, product_idFROM line_itemORDER BY quantity, product_id

Which statement is true concerning the results of executing this statement?

o The results are sorted numerically only.

o The results are sorted alphabetically only.

o The results are sorted numerically and then alphabetically.

o The results are sorted alphabetically and then numerically.

6. The ID column in the CUSTOMER table that corresponds to the CUSTOMER_ID column of the CURR_ORDER table contains null values for rows that need to be displayed.

Which type of join should you use to display the data?

o equijoin

o self join

o outer join

o natural join

7. You query the database with this SQL statement to retrieve data from a table called LINE_ITEM having order_id, line_item_id, product_id and quantity as its columns:

SELECT order_id||'-'||line_item_id||' '||product_id||' '||quantity "Purchase"FROM line_item;

Which component of the SELECT statement is a literal?

o -

o ||

o quantity

o Purchase

8. The STUDENT table contains these columns:

LAST_NAME VARCHAR2(25)FIRST_NAME VARCHAR2(25)EMAIL VARCHAR2(50)

You are writing a SELECT statement to retrieve the names of students that do NOT have an email address.

SELECT last_name||', '||first_name "Student Name"FROM student

Which WHERE clause should you use to complete this statement?

o WHERE email = NULL;

o WHERE email != NULL;

o WHERE email IS NULL;

o WHERE email IS NOT NULL;

9. Evaluate this SQL statement:

SELECT l.order_id, i.description, l.quantityWHERE i.id_number = l.product_idFROM inventory i, line_item lORDER BY l.order_id, i.description;

This statement fails when executed. Which change will correct the problem?

o Reorder the clauses in the statement.

o Remove the table aliases from the FROM clause.

o Use the table names instead of the table aliases in the ORDER BY clause.

o Remove the table alias from the ORDER BY clause, and use only the column name.

10. The INVENTORY table contains these columns:

ID_NUMBER NUMBER PKCATEGORY VARCHAR2(10)LOCATION NUMBERDESCRIPTION VARCHAR2(30)PRICE NUMBER(7,2)QUANTITY NUMBER

You want to return the total of the extended amounts for each item category and location, including only those inventory items that have a price greater than $100.00. The extended amount of each item equals the quantity multiplied by the price. Which SQL statement will return the desired result?

o SELECT category, SUM(price * quantity) TOTAL, location

FROM inventoryWHERE price > 100.00;

o SELECT category, location, SUM(price)

FROM inventoryWHERE price > 100.00GROUP BY category, location;

o SELECT category, SUM(price * quantity) TOTAL, location

FROM inventoryWHERE price > 100.00GROUP BY category;

o SELECT category, SUM(price * quantity) TOTAL, location

FROM inventoryWHERE price > 100.00GROUP BY category, location;

11. You query the database with this SQL statement:

SELECT CONCAT(LOWER(SUBSTR(description, 1, 3)), subject_id) "Subject Description"FROM subject;

In which order are the functions evaluated?

o CONCAT, LOWER, SUBSTR

o SUBSTR, LOWER, CONCAT

o LOWER, SUBSTR, CONCAT

o LOWER, CONCAT, SUBSTR

12. Which SELECT statement should you use to limit the display of account information to those accounts whose finance charge is greater than $75.00?

o SELECT account_id, new_balance, finance_charge

FROM accountWHERE finance_charge > 75.00;

o SELECT account_id, new_balance, finance_charge

FROM accountHAVING finance_charge > 75.00;

o SELECT account_id, new_balance, finance_charge

FROM accountWHERE finance_charge > 75.00GROUP BY finance_charge;

o SELECT account_id, new_balance, finance_charge

FROM accountGROUP BY finance_charge > 75.00;

13. The TRANSACTION table contains these columns:

TRANSACTION_ID NUMBER(9)TRANS_CODE VARCHAR2(5)CUST_ACCOUNT VARCHAR2(12)

A new standard was adopted in your department affecting reports produced by querying the TRANSACTION table. When creating reports, a dash (-) followed by the three characters 'ANI' must be appended to all transaction codes that contain only 3 characters when creating reports. Any leading 'W' on a transaction code must be removed from the resulting data display.

Which query will return the desired results?

o SELECT TRIM('W' (RPAD(trans_code, 7, '-ANI')))

FROM transactionWHERE LENGTH(trans_code) = 3;

o SELECT TRIM('W' FROM (RPAD(trans_code, 3, '-ANI')))

FROM transactionWHERE LENGTH(trans_code) = 3;

o SELECT TRIM(LEADING 'W' FROM (RPAD(trans_code, 7, '-ANI')))

FROM transactionWHERE LENGTH(trans_code) = 3;

o SELECT TRIM(LEADING 'W' FROM (RPAD(trans_code, 3, '-ANI')))

FROM transactionWHERE LENGTH(trans_code) = 3;

14. Evaluate this SQL statement:

SELECT id "Event", SUM(reg_amt) "Registration Amt"FROM eventWHERE reg_amt > 1000.00GROUP BY "Event"ORDER BY 2;

Which clause will cause an error?

o SELECT id "Event", SUM(reg_amt) "Registration Amt"

o FROM event

o WHERE reg_amt > 1000.00

o GROUP BY "Event"

o ORDER BY 2;

15. Which arithmetic operation will return a numeric value?

o '14-FEB-2002' + 25

o '03-JAN-2000' - 30

o '17-JUN-1999' * (480/24)

o TO_DATE('01-JAN-2001') - TO_DATE('01-DEC-2000')

16. The SUPPLIER table contains these columns:

S_ID NUMBER PKNAME VARCHAR2(30)LOCATION_ID NUMBERORDER_DT DATEORDER_AMOUNT NUMBER(8,2)

Which clauses represent valid uses of aggregate functions? (Choose all that apply.)

o FROM MAX(order_dt)

o SELECT SUM(order_dt)

o SELECT SUM(order_amount)

o SELECT MAX(AVG(order_amount))

o WHERE MIN(order_amount) = order_amount

o SELECT location_id, order_dt, MAX(order_amount)

17. The EVENT table contains these columns:

EVENT_ID NUMBEREVENT_NAME VARCHAR2(30)EVENT_DESC VARCHAR2(100)EVENT_TYPE NUMBERLOCATION_ID NUMBER

You have been asked to provide a report of the number of different event types at each location. Which SELECT statement will produce the desired result?

o SELECT UNIQUE(location_id), COUNT(event_type)

FROM eventGROUP BY location_id;

o SELECT COUNT(*), DISTINCT(location_id)

FROM event;

o SELECT DISTINCT (event_type)

FROM eventGROUP BY location_id;

o SELECT location_id, COUNT(DISTINCT event_type)

FROM eventGROUP BY location_id;

o SELECT location_id, MAX(DISTINCT event_type)

FROM eventGROUP BY location_id;

18. Which logical condition operator, used in a WHERE clause, returns TRUE only when both of the conditions are true?

o OR

o NOT

o AND

o LIKE

19. Which statement concerning SQL functions is true?

o All date functions return DATE data type values.

o Character functions can return character or number values.

o Single-row functions can only be used in SELECT and WHERE clauses.

o Conversion functions convert a column definition from one data type to another data type.

20. You must display the order number, line item number, product identification number, and quantity of each item (from a table called line_item) where the quantity ranges from 10 through 100. The order numbers must be in the range of 1500 through 1575. The results must be sorted by order number from lowest to highest and then further sorted by quantity from highest to lowest.

Which statement should you use to display the desired result?

o SELECT order_id, line_item_id, product_id, quantity

FROM line_itemWHERE quantity BETWEEN 9 AND 101AND order_id BETWEEN 1500 AND 1575ORDER BY order_id DESC, quantity DESC;

o SELECT order_id, line_item_id, product_id, quantity

FROM line_itemWHERE (quantity > 10 AND quantity < 100)AND order_id BETWEEN 1500 AND 1575ORDER BY order_id ASC, quantity;

o SELECT order_id, line_item_id, product_id, quantity

FROM line_itemWHERE (quantity > 9 OR quantity < 101)AND order_id BETWEEN 1500 AND 1575ORDER BY order_id, quantity;

o SELECT order_id, line_item_id, product_id, quantity

FROM line_itemWHERE quantity BETWEEN 10 AND 100AND order_id BETWEEN 1500 AND 1575ORDER BY order_id, quantity DESC;

21. The DESCRIBE command displays the column names, whether a column has a NOT NULL constraint, and the ______.

o table owner

o table name

o column data types

o column constraints

22. The INVENTORY table contains these columns:

ID_NUMBER NUMBER PKDESCRIPTION VARCHAR2(30)SUPPLIER_ID NUMBERPRICE NUMBER(7,2)QUANTITY NUMBER

Evaluate this SQL statement:

SELECT id_number, description, SUM(price)FROM inventoryWHERE price > 30.00GROUP BY id_numberORDER BY supplier_id;

Why will this statement cause an error?

o The PRICE column must be included in the GROUP BY clause.

o The ORDER BY clause should immediately follow the WHERE clause.

o The SUPPLIER_ID column is NOT included in the SELECT clause.

o The ORDER BY clause CANNOT be used in a SELECT statement with a GROUP BY

clause.

o The DESCRIPTION and SUPPLIER_ID columns are NOT included in the GROUP BY

clause.

23. The ACCOUNT table contains these columns:

ACCOUNT_ID NUMBER(12)NEW_BALANCE NUMBER(7,2)PREV_BALANCE NUMBER(7,2)FINANCE_CHARGE NUMBER(7,2)

With the least amount of effort, you want to display all of the ACCOUNT table records. Which query should you use?

o SELECT *

FROM account;

o SELECT all

FROM account;

o SELECT any

FROM account;

o SELECT account_id, new_balance, prev_balance, finance_charge

FROM account;

24. Which SELECT statement should you use if you want to display unique combinations of the POSITION and MANAGER values from the EMPLOYEE table?

o SELECT position, manager DISTINCT

FROM employee;

o SELECT position, manager

FROM employee;

o SELECT DISTINCT position, manager

FROM employee;

o SELECT position, DISTINCT manager

FROM employee;

25. Tables EMPLOYEE and TASK are logically related through employee_id which is a primary key in EMPLOYEE and a foreign key in TASK. You need to produce a report containing all employees and all tasks. An employee must be included on the report even if he has no tasks assigned. And all tasks, whether assigned to an employee or not, must also be included on the report.

Which SELECT statement should you use?

o SELECT e.emp_lname, e.emp_fname, t.task_description, t.est_compl_date

FROM employee e, task tWHERE e.employee_id = t.employee_id;

o SELECT e.emp_lname, e.emp_fname, t.task_description, t.est_compl_date

FROM employee e, task tWHERE e.employee_id (+) = t.employee_id;

o SELECT e.emp_lname, e.emp_fname, t.task_description, t.est_compl_date

FROM employee e, task tWHERE e.employee_id = t.employee_id (+);

o SELECT e.emp_lname, e.emp_fname, t.task_description, t.est_compl_date

FROM employee e, task tWHERE e.employee_id (+) = t.employee_id (+);

o None of the options will produce the desired result.

26. Evaluate this SQL statement:

SELECT c.customer_id, o.order_id, o.order_date, p.product_nameFROM customer c, curr_order o, product pWHERE customer.customer_id = curr_order.customer_idAND o.product_id = p.product_idORDER BY o.order_amount;

This statement fails when executed. Which change will correct the problem?

o Use the table name in the ORDER BY clause.

o Remove the table aliases from the WHERE clause.

o Include the ORDER_AMOUNT column in the SELECT list.

o Use the table aliases instead of the table names in the WHERE clause.

o Remove the table alias from the ORDER BY clause and use only the column name.

27. Which three statements concerning explicit data type conversions are true. (Choose three.)

o A number value may be converted to a date value using the TO_DATE function.

o A date value may be converted to a number value using the TO_NUMBER function.

o A character value may be converted to a date value using the TO_DATE function.

o A date value may be converted to a character value using the TO_DATE function.

o A date value may be converted to a character string using the TO_CHAR function.

o A number value may be converted to a character string using the TO_CHAR function.

o A number value may be converted to a character value using the TO_NUMBER function.

28. You query the database with this SQL statement:

SELECT bonusFROM salaryWHERE bonus BETWEEN 1 AND 250OR (bonus IN(190, 500, 600)AND bonus BETWEEN 250 AND 500);

Which value could the statement return?

o 100

o 260

o 400

o 600

29. Which statement about joining tables with a non-equijoin is true?

o The columns being joined must have compatible data types.

o No more than three tables can be joined using a non-equijoin.

o The tables being joined must have primary and foreign keys defined.

o The tables being joined must NOT have any columns with the same name.

o The number of join conditions required is always one less than the number of tables being

joined.

o A WHERE clause must specify a column in one table that directly corresponds to a column

in the second table.

30. The STUDENT table contains these columns:

ID NUMBER(9) LAST_NAME VARCHAR2(25)FIRST_NAME VARCHAR2(25)ENROLL_DATE DATE

You need to display the ENROLL_DATE values in this format:

25th of February 2002

Which SELECT statement could you use?

o SELECT enroll_date('DDspth "of" Month YYYY')

FROM student;

o SELECT TO_CHAR(enroll_date, 'ddth "of" Month YYYY')

FROM student;

o SELECT TO_CHAR(enroll_date, 'DDTH "of" Month YYYY')

FROM student;

o SELECT TO_CHAR(enroll_date, 'DDspth 'of' Month YYYY')

FROM student;