Window Functions · SQL SQL
What is the primary difference between using a standard aggregate function with GROUP BY and using a window function in SQL?
Practice question from Window Functions (SQL SQL), with the correct answer and a step-by-step solution.
easy · MCQ · Q-118ACD
What is the primary difference between using a standard aggregate function with GROUP BY and using a window function in SQL?
- A.Window functions reduce the total number of rows returned in the result set, whereas GROUP BY does not.
- B.Window functions perform calculations across a set of table rows that are somehow related to the current row without collapsing the rows into a single group.Correct answer
- C.GROUP BY can be used with analytic clauses, but window functions cannot be combined with aggregate expressions.
- D.Standard aggregate functions can access previous and subsequent rows directly, whereas window functions cannot.
Solution
Unlike GROUP BY which collapses multiple rows into a single summary row per group, window functions compute an aggregate or rank for each row while preserving the individual rows in the output result set.
More from Window Functions
- Consider the following query: SELECT employeeid, departmentid, salary, ROWNUMBER() OVER (PARTITION BY departmentid ORDER BY salary DESC) as…
- Which ranking window function assigns the same rank to identical values with no gaps in ranking sequence, meaning if two rows share rank 1,…
- What is the default frame specification in a window function when an ORDER BY clause is provided, but no explicit ROWS or RANGE frame is sp…
- Explain the difference between the ROWS and RANGE framing clauses in SQL window functions.
Practise more SQL
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed