Category | Query Example |
---|
Aggregation | GROUP BY , SUM , AVG , COUNT , MAX , MIN |
Window Functions | LAG() , LEAD() , SUM() OVER() , RANK() , PERCENTILE_CONT |
Ranking | RANK() OVER() , DENSE_RANK() , ROW_NUMBER() |
π Aggregation Queries
(Using GROUP BY, COUNT, MAX, SUM, AVG, etc.)
-
Get the count of duplicates in a table
-
Count occurrences of each word in a table column
-
Write a SQL query to get the department-wise highest salary
-
Write a SQL query to find the average salary of employees by department
-
Write a SQL query to calculate the median salary of employees
(if your DB supports PERCENTILE_CONT, e.g., PostgreSQL, SQL Server)
-
Write a SQL query to display the cumulative sum of a column
πͺ Window Functions Queries
(Using RANK, DENSE_RANK, LAG, LEAD, SUM() OVER, etc.)
-
Use LAG and RANK functions in a query
-
Write a SQL query to rank employees based on their performance score
-
Write a SQL query to find the top 3 earners in each department
-
Write a SQL query to find the nth highest salary in a table
(replace N
with the rank you want)
-
Write a SQL query to calculate the median salary of employees
-
Write a SQL query to display the cumulative sum of a column
π Ranking Queries
(Specific to RANK/DENSE_RANK/ROW_NUMBER)
-
Write a SQL query to find the top 3 earners in each department
-
Use RANK function to rank employees based on their performance score
-
Use RANK to find nth highest salary
No comments:
Post a Comment