SQL Partition By vs Group By Quiz

SQL Partition By vs Group By Quiz

Question 1 Which of the following best describes the key difference between GROUP BY and PARTITION BY?

A) GROUP BY groups data and removes individual rows, while PARTITION BY groups data but keeps all rows visible. B) GROUP BY is used only with window functions, while PARTITION BY is used for aggregation. C) PARTITION BY removes duplicates, while GROUP BY counts all rows separately. D) GROUP BY is only used with ORDER BY, while PARTITION BY is used with SUM().

Question 2 Which of the following is true about GROUP BY but not true for PARTITION BY?

A) It can be used with aggregate functions like SUM() and COUNT(). B) It removes individual row details and only returns grouped results. C) It allows ranking functions like ROW_NUMBER() to be applied to each group. D) It can be used inside window functions.

Question 3 Which scenario is best suited for using PARTITION BY instead of GROUP BY?

A) Calculating the total sales per region while keeping all individual transactions visible. B) Counting the number of employees in each department and returning only the department-level count. C) Finding the average salary per job title and returning only the average for each job title. D) Grouping customer orders by month and displaying only the total orders per month.

Question 4 Which of the following is true when using a window function with PARTITION BY?

A) It collapses all rows into a single summary row per partition. B) It can calculate running totals, rankings, or averages within each partition while keeping all rows. C) It requires an ORDER BY clause to function properly. D) It removes duplicates from the dataset.

Question 5 Which of the following statements about GROUP BY and PARTITION BY is false?

A) Both can be used with aggregate functions like SUM() and COUNT(). B) GROUP BY reduces the number of rows in the result, while PARTITION BY does not. C) PARTITION BY must always be used with an ORDER BY clause. D) PARTITION BY organizes data into logical groups for window functions but does not affect row visibility.

Question 6 You are organizing a school’s test scores into groups. If you want to see only the average score per class, which method should you use?

A) Categorizing students by their scores but keeping all test scores visible B) Separating students into classrooms and only keeping the class average C) Assigning a unique ranking to each student within their class based on test scores D) Listing all students with their scores while showing a column with their class average

Question 7 A company wants to calculate the total revenue per store while still keeping all individual sales transactions visible in a report. Which of the following best describes this approach?

A) Group all sales by store and only show the total revenue for each store B) Show all individual sales transactions but include a column displaying the store’s total revenue C) Remove duplicate transactions from each store to get a unique list of sales D) Sort all sales transactions alphabetically and total them at the end

Question 8 Which of the following best explains when you would not use GROUP BY?

A) When you need to find the average age of employees across departments B) When you need to generate rankings within a group while keeping all data visible C) When you want to count how many customers visited each store D) When you want to find the highest total sales per region

Question 9 Imagine a sports league where teams are ranked based on points. You need to assign a rank to each team within its division while keeping all team details visible. Which method is best?

A) Grouping all teams by division and returning only the top-ranked team in each division B) Keeping all teams listed but labeling them with their division’s total points C) Assigning each team a rank within its division while keeping all team details visible D) Removing duplicate team names to ensure each division has only one row

Question 10 A bookstore wants to analyze sales trends over time. If they want to track monthly revenue while keeping daily sales records visible, what approach should they take?

A) Summarizing total sales per month and discarding individual sales records B) Listing all daily sales but including a column showing total revenue per month C) Only keeping sales data from the highest-performing month and removing others D) Sorting daily sales in descending order without tracking totals

要查看或添加评论,请登录

Dr. Austin Stewart的更多文章

社区洞察

其他会员也浏览了