MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:GROUP RANK
Current Quiz Count:30
Progress
0%
Q1
True / False

In MySQL, the RANK() function can be used to assign a unique rank number to each row within a partition of a result set.

Q2
True / False

MySQL’s GROUP BY clause is used to aggregate data across multiple rows.

Q3
True / False

The ROW_NUMBER() function in MySQL assigns a unique sequential integer to rows within a partition of a result set, starting at 1.

Q4
True / False

Question: MySQL 8.0 introduced the DENSE_RANK() function.

Q5
True / False

In MySQL, the RANK() function will generate consecutive rank values, without any gaps, even if there are ties.

Q6
True / False

In MySQL, you can use the RANK() function without a PARTITION BY clause.

Q7
True / False

MySQL's NTILE() function can be used to assign rows to a specified number of buckets and is helpful in ranking.

Q8
True / False

In MySQL, the RANK() function and DENSE_RANK() function will always produce the same result.

Q9
True / False

The RANK() function in MySQL can be combined with the GROUP BY clause to rank groups of rows based on aggregated values.

Q10
True / False

In MySQL certification exams, understanding how RANK(), DENSE_RANK(), and ROW_NUMBER() functions differ is crucial for optimizing query performance.

Q11
Single Choice

Which MySQL function is commonly used to assign a rank within a subgroup of rows in a result set?

Q12
Single Choice

What SQL clause must be used in conjunction with the RANK() function to rank rows within subgroups?

Q13
Single Choice

Which MySQL function assigns the same rank to rows with identical values and skips the next rank(s)?

Q14
Single Choice

What will be the rank of Alice if you apply the following SQL query?

SQL Code
Given the following table sales:

Salesperson	Region	Sales
Alice	East	500
Bob	East	700
Carol	East	500
Dave	West	450
Eve	West	700

SELECT Salesperson, Sales,
 RANK() OVER (PARTITION BY Region ORDER BY Sales DESC) AS Rank
FROM sales;
Q15
Single Choice

. In a ranking query, how would you ensure that gaps in ranks do not occur when there are ties in a subgroup?

Q16
Single Choice

What will be the output for Jill if you use the following SQL query?

SQL Code
Given the following table employees:

Employee	Department	Salary
John	HR	60000
Jane	HR	75000
Jack	IT	80000
Jill	IT	75000
Joe	IT	75000
SELECT Employee, Department, Salary,
 DENSE_RANK() OVER (PARTITION BY Department ORDER BY Salary DESC) AS Rank
FROM employees;
Q17
Single Choice

What will be the rank of the Fridge if the following SQL query is executed?

SQL Code
Consider the following table products:

Product	Category	Price
Laptop	Electronics	1000
Phone	Electronics	800
TV	Electronics	1200
Blender	Kitchen	200
Toaster	Kitchen	150
Fridge	Kitchen	700

SELECT Product, Category, Price,
 RANK() OVER (PARTITION BY Category ORDER BY Price DESC) AS Rank
FROM products;
Q18
Single Choice

What is the difference between ROW_NUMBER() and RANK() in MySQL when applied within subgroups?

Q19
Single Choice

What will be the output for Anne if the following SQL query is executed?

SQL Code
Consider the following sales table:

Salesperson	Region	Sales
Anne	North	400
Beth	North	500
Claire	North	500
Dave	South	700
Ella	South	700

SELECT Salesperson, Region, Sales,
 DENSE_RANK() OVER (PARTITION BY Region ORDER BY Sales DESC) AS Rank
FROM sales;
Q20
Single Choice

You 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?

Q21
Multiple Choice

Which 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;
Q22
Multiple Choice

Identify 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;
Q23
Multiple Choice

Which 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;
Q24
Multiple Choice

Determine 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;
Q25
Multiple Choice

Which 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;
Q26
Multiple Choice

Which 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;
Q27
Multiple Choice

Identify 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;
Q28
Multiple Choice

Which 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;
Q29
Multiple Choice

Determine 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;
Q30
Multiple Choice

Which 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;