Loading topic
AVG or SUM reduces many rows to one value. An analytic function computes a value from a set of related rows but keeps every input row in the result. This chapter explains that difference and the rules that follow from it. Later chapters cover ROW_NUMBER, RANK, `4 min readSELECT, WHERE, and ORDER BY in Oracle SQL, you know GROUP BY with aggregates such as SUM and COUNT, and you can use an inline view. The chapter covers the structure of the OVER clause, which is the part of the syntax that makes a function analytic. La5 min readSELECT, WHERE, and ORDER BY queries in Oracle SQL. It also assumes you know GROUP BY with aggregates such as SUM and COUNT, and that you have seen the basic shape of an OVER clause. Here you will look at one part of that clause, PARTITION BY. It dec4 min readGROUP BY queries and have seen the OVER clause with PARTITION BY. It covers the ORDER BY that goes inside OVER: what it controls, how it differs from the query's ORDER BY, and the details that change results.5 min readROW_NUMBER assigns a sequential integer to each row of a query result, restarting the count for every group you define. This chapter covers its syntax, its behavior with ties and NULLs, and the inline-view pattern you need to filter on the number it produces.4 min readOVER (PARTITION BY ... ORDER BY ...) clause and have used ROW_NUMBER. It covers how RANK and DENSE_RANK treat tied values, how to pick between them, and the mistakes that cause wrong results.5 min readOVER clause, including PARTITION BY and ORDER BY. It also assumes you know the logical order of WHERE, GROUP BY, and HAVING, and that you can write an inline view. Here you learn two things. The first is which clauses may co5 min readPARTITION BY and ORDER BY inside OVER. It also assumes you know what ROW_NUMBER, RANK and DENSE_RANK return, and that you can read an inline view (a subquery in the FROM clause). Here you combine those pieces to answer a very comm4 min readLAG is an analytic function that returns a column value from an earlier row in the same ordered result set. It does this without a self-join. This chapter assumes you can write an OVER clause with PARTITION BY and ORDER BY. It also assumes you know how ROW_NUMBER orders rows inside a parti5 min readLEAD is an analytic function that returns a column value from a row that follows the current row. It is the mirror image of LAG, and most of what you learned about LAG applies unchanged. This chapter assumes you know OVER, PARTITION BY, the window ORDER BY, and the LAG offset and defau5 min readLAG(amount) and LEAD(amount) with one argument. Both functions take up to three arguments, and the second and third change what a query returns, especially at the edges of a partition. This chapter assumes you can write an OVER clause with PARTITION BY and ORDER BY, a4 min readROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...), use inline views, and run DELETE statements inside a transaction. It applies those pieces to one job: finding duplicate rows, choosing which copy to keep, and deleting the rest.5 min readLAG and LEAD with an OVER (ORDER BY ...) clause and know the offset and default arguments. It covers what happens when the neighbouring row holds a NULL, and how to make Oracle look past it.5 min readROW_NUMBER, RANK, LAG, and LEAD with PARTITION BY and ORDER BY. It covers what these functions cost, how to reduce that cost, and how to check your work.6 min read