Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CNC314 DATABASE Fall 23.

24
QUIZ (Model B)

1. Find the error and correct.

Display the last name, salary, and commission for all employees
who earn commissions. Sort data in descending order of salary
and commissions.

SELECT last_name, salary, commission_pct

FROM employees

WHERE commission_pct IS NOT NULL ORDER BY salary DESC,


commission_pct DESC;

2. Complete the code.


Display the last name, hire date, and day of the week on which
the employee started. Label the column DAY. Order the results
by the day of the week star ng with Monday.

SELECT last_name, hire_date,

…TO_CHAR(hire_date, 'DAY') DAY…………………………………………………..

FROM employees

ORDER BY TO_CHAR(hire_date - 1, 'd');

3. Write a query to display each department’s name, loca on,


number of employees, and the average salary for all employees
in that department. Label the columns Name, Loca on,
Number of People, and Salary, respec vely. Round the average
salary to two decimal places.
CNC314 DATABASE Fall 23.24
QUIZ (Model B)
SELECT d.department_name "Name", d.loca on_id
"Loca on", COUNT(*) "Number of People",
ROUND(AVG(salary),2) "Salary"
FROM employees e, departments d
WHERE e.department_id = d.department_id
GROUP BY d.department_name, d.loca on_id;

You might also like