100% found this document useful (1 vote)
3K views

Database Programming Section 8 Quiz

The document is a quiz on database programming concepts related to group functions. It contains 15 multiple choice questions testing understanding of functions like COUNT, AVG, MAX, and SUM. Key points covered are: - COUNT returns the number of rows - AVG calculates the average of non-null values - MAX and MIN return the highest and lowest values - Group functions can be used with the SELECT statement to aggregate data from tables and columns.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views

Database Programming Section 8 Quiz

The document is a quiz on database programming concepts related to group functions. It contains 15 multiple choice questions testing understanding of functions like COUNT, AVG, MAX, and SUM. Key points covered are: - COUNT returns the number of rows - AVG calculates the average of non-null values - MAX and MIN return the highest and lowest values - Group functions can be used with the SELECT statement to aggregate data from tables and columns.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Database Programming Section 8 Quiz

Section 8 Quiz
(Answer all questions in this section)

1. You need to calculate the average salary of employees in


each department. Which group function will you use? Mark for
Review
(1) Points

MEAN

AVERAGE

AVG (*)

MEDIAN

[Correct] Correct
2. Which group function would you use to display the average
price of all products in the PRODUCTS table? Mark for Review
(1) Points

SUM

COUNT

AVG (*)

MAX

[Correct] Correct

3. The CUSTOMER table contains these columns:

CUSTOMER_ID NUMBER(9)
FIRST_NAME VARCHAR2(25)
LAST_NAME VARCHAR2(30)
CREDIT_LIMIT NUMBER (7,2)
CATEGORY VARCHAR2(20)

You need to calculate the average credit limit for all the customers in
each category. The average should be calculated based on all the
rows in the table excluding any customers who have not yet been
assigned a credit limit value.
Which group function should you use to calculate this value?
Mark for Review
(1) Points

STDDEV

SUM

COUNT

AVG (*)
[Correct] Correct

4. You can use GROUP functions in all clauses of a SELECT


statement. True or False? Mark for Review
(1) Points

True

False (*)

[Correct] Correct

5. The following statement will work, even though it contains


more than one GROUP function:
SELECT AVG(salary), MAX(salary), MIN(salary), SUM(salary)
FROM employees;
True or False?
Mark for Review
(1) Points

True (*)

False

[Correct] Correct
(Answer all questions in this section)

6. The TRUCKS table contains these columns:

TRUCKS:
TYPE VARCHAR2(30)
YEAR DATE
MODEL VARCHAR2(20)
PRICE NUMBER(10)

Which SELECT statement will return the average price for the 4x4
model?
Mark for Review
(1) Points

SELECT AVG(price), model


FROM trucks
WHERE model IS '4x4';

SELECT AVG(price)
FROM trucks
WHERE model IS '4x4';

SELECT AVG(price)
FROM trucks
WHERE model IS 4x4;

SELECT AVG(price)
FROM trucks
WHERE model = '4x4';

(*)

[Correct] Correct

7. Which group function would you use to display the highest


salary value in the EMPLOYEES table? Mark for Review
(1) Points

COUNT

MIN

AVG

MAX (*)
[Correct] Correct

8. Given the following data in the employees table


(employee_id, salary, commission_pct)

DATA: (143, 2600, null


144, 2500, null
149, 10500, .2
174, 11000, .3
176, 8600, .2
178, 7000, .15)

What is the result of the following statement:

SELECT AVG(commission_pct)
FROM employees
WHERE employee_id IN( 143,144,149,174,176,178);
Mark for Review
(1) Points

0.0425
0.2125 (*)

This statement is invalid

1.2125

[Incorrect] Incorrect. Refer to Section 8 Lesson 1.

9. Evaluate this SELECT statement:

SELECT COUNT(*)
FROM products;

Which statement is true?


Mark for Review
(1) Points
An error occurs because no WHERE clause is included in the
SELECT statement.

The number of rows in the table is displayed. (*)

An error occurs due to an error in the SELECT clause.

The number of unique PRODUCT_IDs in the table is displayed.

[Incorrect] Incorrect. Refer to Section 8 Lesson 2.

10. Using your existing knowledge of the employees table,


would the following two statements produce the same result?

SELECT COUNT(*)
FROM employees;

SELECT COUNT(commission_pct)
FROM employees;
Mark for Review
(1) Points

Yes

The first statement is invalid

The second statement is invalid

No (*)

[Correct] Correct
(Answer all questions in this section)

11. Which SELECT statement will calculate the number of


rows in the PRODUCTS table? Mark for Review
(1) Points
SELECT COUNT (*) FROM products; (*)

SELECT COUNT FROM products;

SELECT ROWCOUNT FROM products;

SELECT COUNT(products);

[Correct] Correct

12. Evaluate this SQL statement:

SELECT COUNT (amount)


FROM inventory;

What will occur when the statement is issued?


Mark for Review
(1) Points

The statement will return the total number of rows in the AMOUNT
column.

The statement will count the number of rows in the INVENTORY


table where the AMOUNT column is not null. (*)

The statement will replace all NULL values that exist in the
AMOUNT column.

The statement will return the greatest value in the INVENTORY


table.

[Correct] Correct

13. To include null values in the calculations of a group


function, you must: Mark for Review
(1) Points
Convert the null to a value using the NVL( ) function (*)

Precede the group function name with NULL

Group functions can never use null values

Count the number of null values in that column using COUNT

[Correct] Correct

14. The STYLES table contains this data:

STYLE_ID STYLE_NAME CATEGORY COST


895840 SANDAL 85940 12.00
968950 SANDAL 85909 10.00
869506 SANDAL 89690 15.00
809090 LOAFER 89098 10.00
890890 LOAFER 89789 14.00
857689 HEEL 85940 11.00
758960 SANDAL 86979

You issue this SELECT statement:

SELECT COUNT(category)
FROM styles;

Which value is displayed?


Mark for Review
(1) Points

7 (*)

6
The statement will NOT execute successfully.

[Correct] Correct

15. The EMPLOYEES table contains these columns:

EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
SALARY NUMBER(7,2)
DEPARTMENT_ID NUMBER(9)

You need to display the number of employees whose salary is greater


than $50,000? Which SELECT would you use?
Mark for Review
(1) Points

SELECT * FROM employees


WHERE salary > 50000;
SELECT * FROM employees
WHERE salary < 50000;

SELECT COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY employee_id, last_name, first_name, salary,
department_id;

SELECT COUNT(*)
FROM employees
WHERE salary < 50000;

SELECT COUNT(*)
FROM employees
WHERE salary > 50000;

(*)
[Correct] Correct

You might also like