PostgreSQL Database Quiz Questions

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

The RANK() function in PostgreSQL can be used to assign a unique rank number to each row within a partition of a result set.

Q2
True / False

The GROUP BY clause in PostgreSQL is used to rank rows.

Q3
True / False

In PostgreSQL, the DENSE_RANK() function produces the same result as the RANK() function if there are no duplicate values.

Q4
True / False

The RANK() function in PostgreSQL will always increment the rank by 1 regardless of duplicate values.

Q5
True / False

The PARTITION BY clause is necessary when using the RANK() function in PostgreSQL to rank rows within groups.

Q6
True / False

The ROW_NUMBER() function in PostgreSQL provides the same ranking as the RANK() function.

Q7
True / False

In PostgreSQL, the RANK() function can be used in conjunction with ORDER BY to rank rows based on a specific column.

Q8
True / False

The CUME_DIST() function in PostgreSQL returns the rank of the current row as a percentage of the total rows in the partition.

Q9
True / False

Using the NTILE() function in PostgreSQL, you can divide rows into a specified number of approximately equal groups and assign a group rank to each row.

Q10
True / False

The RANK() function in PostgreSQL can be used directly within the WHERE clause to filter results based on rank.

Q11
Single Choice

In PostgreSQL, which function is commonly used to assign a rank to rows within a partition of a result set?

Q12
Single Choice

What is the difference between the RANK() and DENSE_RANK() functions in PostgreSQL?

Q13
Single Choice

Which SQL clause is necessary when using RANK() to partition rows in PostgreSQL?

Q14
Single Choice

How would you rank employees by salary within each department using PostgreSQL?

SQL Code
SELECT
 employee_id,
 department_id,
 salary,
 RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees;
What does the RANK() function do in this query?
Q15
Single Choice

Given the following PostgreSQL query, what would be the rank of an employee with a salary of 50000 if there are two other employees with the same salary in the same department?

SQL Code
SELECT
 employee_id,
 department_id,
 salary,
 RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees;
Q16
Single Choice

How can you modify the PostgreSQL query to ensure no ranks are skipped, even if there are ties?

SQL Code
SELECT
 employee_id,
 department_id,
 salary,
 _______ OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank
FROM employees;
Q17
Single Choice

Consider the following PostgreSQL query:

SQL Code
SELECT
 product_id,
 category_id,
 price,
 RANK() OVER (PARTITION BY category_id ORDER BY price DESC) AS rank
FROM products;
If there are two products with the same highest price in the same category, what will be the rank of the next product in that category?
Q18
Single Choice

In PostgreSQL, which of the following queries will rank items in descending order of quantity sold, with the highest quantity ranked as 1, without skipping ranks if there are ties?

SQL Code
SELECT
 item_id,
 category_id,
 quantity_sold,
 _______ OVER (PARTITION BY category_id ORDER BY quantity_sold DESC) AS rank
FROM sales;
Q19
Single Choice

How can you include only the top 3 ranked items in each category using the following PostgreSQL query?

SQL Code
SELECT
 item_id,
 category_id,
 price,
 RANK() OVER (PARTITION BY category_id ORDER BY price DESC) AS rank
FROM items
_______;
Q20
Single Choice

Given the following PostgreSQL table sales with columns salesperson_id, region_id, and total_sales, how can you rank salespersons by their total sales within each region and display only those with a rank of 1 or 2?

SQL Code
SELECT
 salesperson_id,
 region_id,
 total_sales,
 RANK() OVER (PARTITION BY region_id ORDER BY total_sales DESC) AS rank
FROM sales
_______;
Q21
Multiple Choice

Which of the following SQL queries correctly ranks employees within their department based on their salary?

Q22
Multiple Choice

Which SQL queries correctly use GROUP RANK functions to list products by category in order of sales?

Q23
Multiple Choice

Which of the following SQL queries correctly rank departments by their total budget?

Q24
Multiple Choice

Which SQL queries correctly implement group ranking for employees based on their hire date within each department?

Q25
Multiple Choice

Which SQL queries correctly rank customers by their total purchase amount within each region?

Q26
Multiple Choice

Which SQL queries correctly implement ranking to find the top 3 products by sales within each category?

Q27
Multiple Choice

Which SQL queries correctly use the GROUP RANK functions to rank students by their GPA within each class?

Q28
Multiple Choice

Which SQL queries correctly rank branches by their total revenue within each state?

Q29
Multiple Choice

Which SQL queries correctly implement group ranking for sales representatives based on their quarterly sales?

Q30
Multiple Choice

Which SQL queries correctly rank projects by their completion percentage within each department?