Q1
True / FalseIn MySQL, the RANK() function can be used to assign a unique rank number to each row within a partition of a result set.
The RANK() function can assign the same rank to rows with identical values within the partition, not necessarily a unique rank.
Q2
True / FalseMySQL’s GROUP BY clause is used to aggregate data across multiple rows.
The GROUP BY clause groups rows that have the same values into summary rows, like "find the number of customers in each country".
Q3
True / FalseThe ROW_NUMBER() function in MySQL assigns a unique sequential integer to rows within a partition of a result set, starting at 1.
The ROW_NUMBER() function assigns a unique number to each row within the partition, starting from 1.
Q4
True / FalseQuestion: MySQL 8.0 introduced the DENSE_RANK() function.
The DENSE_RANK() function was introduced in MySQL 8.0, which provides rank values without gaps in the ranking.
Q5
True / FalseIn MySQL, the RANK() function will generate consecutive rank values, without any gaps, even if there are ties.
The RANK() function will leave gaps in the ranking sequence if there are ties (e.g., if two rows are tied for rank 1, the next rank will be 3).
Q6
True / FalseIn MySQL, you can use the RANK() function without a PARTITION BY clause.
The RANK() function can be used without the PARTITION BY clause, but it will treat the entire result set as a single partition.
Q7
True / FalseMySQL's NTILE() function can be used to assign rows to a specified number of buckets and is helpful in ranking.
The NTILE() function distributes rows into a specified number of buckets, which can be useful in ranking and distribution tasks.
Q8
True / FalseIn MySQL, the RANK() function and DENSE_RANK() function will always produce the same result.
The RANK() function produces ranks with gaps if there are ties, whereas the DENSE_RANK() function produces consecutive ranks without gaps.
Q9
True / FalseThe RANK() function in MySQL can be combined with the GROUP BY clause to rank groups of rows based on aggregated values.
You can use the RANK() function with the GROUP BY clause to rank groups of rows based on aggregated values, though it may require subqueries or CTEs to achieve the desired result.
Q10
True / FalseIn MySQL certification exams, understanding how RANK(), DENSE_RANK(), and ROW_NUMBER() functions differ is crucial for optimizing query performance.
Knowledge of these ranking functions and their differences is essential for certification exams as they can impact query results and performance optimization.
Q20
Single ChoiceYou need to assign ranks to employees within their departments and also rank the departments based on the highest employee salary in each department. Which of the following SQL queries accomplishes this?
The query uses RANK() for both ranking within the department and across departments. The subquery MAX(Salary) OVER (PARTITION BY Department) is used to rank departments based on their highest salary.
Q21
Multiple ChoiceWhich SQL query ranks employees based on their salaries within each department using the RANK() function?
SQL Code
SELECT employee_name, department_id, salary,
RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees;
The RANK() function ranks employees within each department based on their salaries in descending order. The PARTITION BY clause groups the employees by department.
Q22
Multiple ChoiceIdentify the SQL query that uses DENSE_RANK() to assign ranks to students based on their scores within each class.
SQL Code
SELECT student_name, class_id, score,
DENSE_RANK() OVER (PARTITION BY class_id ORDER BY score DESC) AS rank
FROM students;
The DENSE_RANK() function assigns ranks to students within each class based on their scores in descending order, without gaps in the ranking sequence.
Q23
Multiple ChoiceWhich SQL query ranks products based on their sales within each category using the ROW_NUMBER() function?
SQL Code
SELECT product_name, category_id, sales,
ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY sales DESC) AS rank
FROM products;
The ROW_NUMBER() function assigns a unique rank to each product within its category based on sales in descending order, with no ties.
Q24
Multiple ChoiceDetermine the SQL query that uses the RANK() function to assign ranks to employees based on their performance scores within each department.
SQL Code
SELECT employee_name, department_id, performance_score,
RANK() OVER (PARTITION BY department_id ORDER BY performance_score DESC) AS rank
FROM employees;
The RANK() function ranks employees within each department based on their performance scores in descending order, with gaps in the ranking sequence for ties.
Q25
Multiple ChoiceWhich SQL query uses DENSE_RANK() to rank products based on their ratings within each supplier group?
SQL Code
SELECT product_name, supplier_id, rating,
DENSE_RANK() OVER (PARTITION BY supplier_id ORDER BY rating DESC) AS rank
FROM products;
The DENSE_RANK() function assigns ranks to products within each supplier group based on their ratings in descending order, ensuring no gaps in the ranking sequence.
Q26
Multiple ChoiceWhich SQL query ranks students based on their marks within each subject using the RANK() function?
SQL Code
SELECT student_name, subject_id, marks,
RANK() OVER (PARTITION BY subject_id ORDER BY marks DESC) AS rank
FROM student_scores;
The RANK() function assigns ranks to students within each subject based on their marks in descending order, allowing for ties and gaps in the ranking.
Q27
Multiple ChoiceIdentify the SQL query that uses ROW_NUMBER() to assign unique ranks to employees based on their years of experience within each department.
SQL Code
SELECT employee_name, department_id, experience_years,
ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY experience_years DESC) AS rank
FROM employees;
The ROW_NUMBER() function assigns unique ranks to employees within each department based on their years of experience in descending order, with no ties.
Q28
Multiple ChoiceWhich SQL query uses RANK() to determine the top 3 performers in each department based on their performance scores?
SQL Code
SELECT * FROM (
SELECT employee_name, department_id, performance_score,
RANK() OVER (PARTITION BY department_id ORDER BY performance_score DESC) AS rank
FROM employees
) AS ranked_data
WHERE rank <= 3;
The RANK() function ranks employees within each department based on performance scores. The outer query then filters the top 3 performers in each department.
Q29
Multiple ChoiceDetermine the SQL query that ranks salespersons based on their total sales within each region using DENSE_RANK().
SQL Code
SELECT salesperson_name, region_id, total_sales,
DENSE_RANK() OVER (PARTITION BY region_id ORDER BY total_sales DESC) AS rank
FROM sales_data;
The DENSE_RANK() function ranks salespersons within each region based on their total sales in descending order, ensuring no gaps in the ranking sequence.
Q30
Multiple ChoiceWhich SQL query uses ROW_NUMBER() to find the top 5 products by revenue within each category?
SQL Code
SELECT * FROM (
SELECT product_name, category_id, revenue,
ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY revenue DESC) AS rank
FROM products
) AS ranked_products
WHERE rank <= 5;
The ROW_NUMBER() function assigns a unique rank to each product within its category based on revenue in descending order, and the outer query filters the top 5 products in each category.