Q1
True / FalseIn Oracle, the RANK function is used to assign a rank to each row within a partition of a result set.
The RANK function assigns a rank to each row within a partition of a result set, with the same rank for rows with equal values.
Q2
True / FalseThe DENSE_RANK function in Oracle assigns unique ranks without gaps between the ranks.
The DENSE_RANK function assigns ranks to rows within a partition without gaps between the rank values.
Q3
True / FalseIn Oracle, the RANK function can be used without the OVER clause.
The RANK function must be used with the OVER clause, which defines the partitioning and ordering of rows.
Q4
True / FalseIn Oracle, you can use the RANK function to rank rows within each group created by the GROUP BY clause.
The RANK function can be used with the PARTITION BY clause to rank rows within each group created by the GROUP BY clause.
Q5
True / FalseThe RANK function in Oracle assigns the same rank to rows with equal values, but leaves gaps in the ranking sequence.
The RANK function assigns the same rank to rows with equal values and leaves gaps in the ranking sequence for ties.
Q6
True / FalseIn Oracle, the NTILE function can be used to divide rows into a specified number of roughly equal groups.
The NTILE function divides rows into a specified number of roughly equal groups, assigning a unique group number to each row.
Q7
True / FalseIn Oracle, the RANK function can be used in a WHERE clause to filter rows based on their rank.
The RANK function cannot be used directly in a WHERE clause. Instead, it must be used in a subquery or common table expression (CTE), and then filtered in an outer query.
Q8
True / FalseThe ROW_NUMBER function in Oracle assigns a unique sequential integer to rows within a partition, without regard to ties.
The ROW_NUMBER function assigns a unique sequential integer to each row within a partition, even if there are ties.
Q9
True / FalseIn Oracle, you can use window functions like RANK and DENSE_RANK in combination with analytic functions to perform complex calculations over partitions of data.
Window functions like RANK and DENSE_RANK can be used alongside analytic functions to perform complex calculations over partitions of data.
Q10
True / FalseThe Oracle Certified Professional (OCP) exam includes knowledge on using ranking functions like RANK, DENSE_RANK, and ROW_NUMBER effectively, understanding their syntax, and optimizing their performance in SQL queries.
The OCP certification covers advanced topics, including the effective use of ranking functions, understanding their syntax, and optimizing their performance in SQL queries.
Q21
Multiple ChoiceWhich SQL code snippet demonstrates using the `RANK` function to assign ranks within a department based on salary?
SQL Code
SELECT employee_id, department_id, salary,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees;
Options A, B, and C correctly demonstrate the use of the `RANK` function to assign ranks within each department based on descending salary. Option D is incorrect because it does not use the `RANK` function.
Q22
Multiple ChoiceWhich SQL code snippet demonstrates using the `DENSE_RANK` function to handle ranking when duplicate values exist?
SQL Code
SELECT employee_id, department_id, salary,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_dense_rank
FROM employees;
Options A, B, and C correctly demonstrate the use of the `DENSE_RANK` function to handle ranking where duplicate values exist, assigning consecutive ranks without gaps. Option D is incorrect because it does not use the `DENSE_RANK` function.
Q23
Multiple ChoiceWhich SQL code snippet demonstrates using the `ROW_NUMBER` function to assign unique row numbers within each department?
SQL Code
SELECT employee_id, department_id, salary,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS row_num
FROM employees;
Options A, B, and C correctly demonstrate the use of the `ROW_NUMBER` function to assign unique row numbers within each department based on descending salary. Option D is incorrect because it does not use the `ROW_NUMBER` function.
Q24
Multiple ChoiceWhich SQL code snippet demonstrates using `RANK` in conjunction with `GROUP BY` to rank departments by their average salary?
SQL Code
SELECT department_id, AVG(salary) AS avg_salary,
RANK() OVER (ORDER BY AVG(salary) DESC) AS dept_rank
FROM employees
GROUP BY department_id;
Options A, B, and C correctly demonstrate the use of `RANK` in conjunction with `GROUP BY` to rank departments based on their average salary. Option D is incorrect because it does not use the `RANK` function.
Q25
Multiple ChoiceWhich SQL code snippet demonstrates using `NTILE` to divide employees into quartiles based on their salary?
SQL Code
SELECT employee_id, salary,
NTILE(4) OVER (ORDER BY salary DESC) AS salary_quartile
FROM employees;
Options A, B, and C correctly demonstrate the use of the `NTILE` function to divide employees into quartiles based on descending salary. Option D is incorrect because it does not use the `NTILE` function.
Q26
Multiple ChoiceWhich SQL code snippet demonstrates advanced use of the `RANK` function to rank employees within each department based on their performance score?
SQL Code
SELECT employee_id, department_id, performance_score,
RANK() OVER (PARTITION BY department_id ORDER BY performance_score DESC) AS performance_rank
FROM employees;
Options A, B, and C correctly demonstrate the advanced use of the `RANK` function to rank employees within each department based on performance. Option D is incorrect because it does not use the `RANK` function.
Q27
Multiple ChoiceWhich SQL code snippet demonstrates advanced use of the `DENSE_RANK` function in a nested subquery to rank employees by hire date within their department?
SQL Code
SELECT employee_id, department_id, hire_date
FROM (SELECT employee_id, department_id, hire_date,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY hire_date) AS hire_rank
FROM employees) subquery
WHERE hire_rank = 1;
Options A, B, and C correctly demonstrate the advanced use of `DENSE_RANK` within a subquery to rank employees by hire date. Option D is incorrect because it does not use the `DENSE_RANK` function.
Q28
Multiple ChoiceWhich SQL code snippet demonstrates certification-level use of the `RANK` function to determine the top 3 highest-paid employees in each department?
SQL Code
SELECT employee_id, department_id, salary
FROM (SELECT employee_id, department_id, salary,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees) subquery
WHERE salary_rank <= 3;
Options A, B, and C correctly demonstrate the certification-level use of `RANK` to identify the top 3 highest-paid employees in each department. Option D is incorrect because it does not use the `RANK` function.
Q29
Multiple ChoiceWhich SQL code snippet demonstrates certification-level use of the `RANK` function combined with a window function to calculate cumulative salary?
SQL Code
SELECT employee_id, department_id, salary,
SUM(salary) OVER (ORDER BY RANK() OVER (PARTITION BY department_id ORDER BY salary DESC)) AS cumulative_salary
FROM employees;
Options A, B, and C correctly demonstrate the certification-level use of `RANK` combined with a window function to calculate cumulative salary. Option D is incorrect because it does not use the `RANK` function.
Q30
Multiple ChoiceWhich SQL code snippet demonstrates certification-level use of the `DENSE_RANK` function to identify the highest-performing department?
SQL Code
SELECT department_id, performance_score,
DENSE_RANK() OVER (ORDER BY AVG(performance_score) DESC) AS dept_rank
FROM employees
GROUP BY department_id
HAVING DENSE_RANK() = 1;
Options A, B, and C correctly demonstrate the certification-level use of `DENSE_RANK` to identify the highest-performing department based on average performance score. Option D is incorrect because it does not use the `DENSE_RANK` function.