Q1
True / FalseThe RANK() function in PostgreSQL can be used to assign a unique rank number to each row within a partition of a result set.
The RANK() function assigns a rank to each row within the partition of the result set, with gaps in ranking where there are ties.
Q2
True / FalseThe GROUP BY clause in PostgreSQL is used to rank rows.
The GROUP BY clause is used to group rows that have the same values in specified columns into aggregate data, not to rank rows.
Q3
True / FalseIn PostgreSQL, the DENSE_RANK() function produces the same result as the RANK() function if there are no duplicate values.
If there are no duplicate values, both DENSE_RANK() and RANK() will produce the same ranking result.
Q4
True / FalseThe RANK() function in PostgreSQL will always increment the rank by 1 regardless of duplicate values.
The RANK() function skips ranks when there are duplicate values, causing gaps in the ranking sequence.
Q5
True / FalseThe PARTITION BY clause is necessary when using the RANK() function in PostgreSQL to rank rows within groups.
While PARTITION BY is often used to rank rows within groups, it is not mandatory. Without PARTITION BY, the function will rank the entire result set.
Q6
True / FalseThe ROW_NUMBER() function in PostgreSQL provides the same ranking as the RANK() function.
The ROW_NUMBER() function assigns a unique number to each row in the result set, without gaps, unlike the RANK() function which can have gaps when there are ties.
Q7
True / FalseIn PostgreSQL, the RANK() function can be used in conjunction with ORDER BY to rank rows based on a specific column.
The RANK() function is typically used with the ORDER BY clause to determine the rank of rows based on the values of one or more columns.
Q8
True / FalseThe CUME_DIST() function in PostgreSQL returns the rank of the current row as a percentage of the total rows in the partition.
The CUME_DIST() function calculates the cumulative distribution of a value in a set of values, returning the rank of the current row as a percentage.
Q9
True / FalseUsing 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.
The NTILE() function divides an ordered result set into a specified number of groups and assigns a group number to each row.
Q10
True / FalseThe RANK() function in PostgreSQL can be used directly within the WHERE clause to filter results based on rank.
The RANK() function cannot be used directly in the WHERE clause because RANK() is a window function and is computed after the WHERE clause is processed. To filter based on rank, you need to use a subquery or a common table expression (CTE).
Q21
Multiple ChoiceWhich of the following SQL queries correctly ranks employees within their department based on their salary?
The ROW_NUMBER() function with PARTITION BY is commonly used to rank items within a group, such as employees within a department.
Q22
Multiple ChoiceWhich SQL queries correctly use GROUP RANK functions to list products by category in order of sales?
RANK(), DENSE_RANK(), and ROW_NUMBER() are all functions that can be used to rank items within a group, each serving slightly different purposes.
Q23
Multiple ChoiceWhich of the following SQL queries correctly rank departments by their total budget?
RANK() and DENSE_RANK() can be used to rank groups, such as departments, based on aggregate values like total budget.
Q24
Multiple ChoiceWhich SQL queries correctly implement group ranking for employees based on their hire date within each department?
ROW_NUMBER(), RANK(), and DENSE_RANK() are functions that can be used to rank employees within each department based on a specific order, such as hire date.
Q25
Multiple ChoiceWhich SQL queries correctly rank customers by their total purchase amount within each region?
The PARTITION BY clause is used with ranking functions to group data before applying the ranking logic, allowing you to rank customers within each region.
Q26
Multiple ChoiceWhich SQL queries correctly implement ranking to find the top 3 products by sales within each category?
Ranking functions like ROW_NUMBER() can be used in combination with a WHERE clause to limit the results to the top N records within each group.
Q27
Multiple ChoiceWhich SQL queries correctly use the GROUP RANK functions to rank students by their GPA within each class?
Using PARTITION BY with ranking functions allows you to create ranks for students within each class based on their GPA.
Q28
Multiple ChoiceWhich SQL queries correctly rank branches by their total revenue within each state?
The PARTITION BY clause can be used to rank branches within a specific state, allowing you to compare revenue across branches within that group.
Q29
Multiple ChoiceWhich SQL queries correctly implement group ranking for sales representatives based on their quarterly sales?
RANK(), DENSE_RANK(), and ROW_NUMBER() functions can be applied within a group to rank records such as sales representatives within each region.
Q30
Multiple ChoiceWhich SQL queries correctly rank projects by their completion percentage within each department?
Ranking functions like RANK(), DENSE_RANK(), and ROW_NUMBER() can be used to rank projects within a department based on completion percentage.