LAG, LEAD, FIRST_VALUE and LAST_VALUE
Reading other rows from the current row: the previous value, the next value, and the first or last in the window - with the LAST_VALUE frame trap.
Notes related to SQL.
131 notes tagged
Reading other rows from the current row: the previous value, the next value, and the first or last in the window - with the LAST_VALUE frame trap.
The four ranking functions, how each handles ties, and the top N per group pattern that makes ROW_NUMBER the most used window function in SQL.
Window functions compute across related rows without collapsing them. Learn the OVER clause, PARTITION BY, window ORDER BY, and how they differ from G...
When you can INSERT or UPDATE through a view, what WITH CHECK OPTION protects against, and an honest comparison of views, tables and materialised view...
A view is a stored query you can select from like a table. Learn CREATE VIEW, how views are executed, and the four jobs they do well.
The three anomalies normalisation prevents, and the disciplined way to reintroduce redundancy when reads genuinely demand it.
The formal notation behind normalisation, and the stricter normal form that catches what 3NF allows through when candidate keys overlap.
Normalisation worked through on one table: remove repeating groups, then partial dependencies, then transitive ones - with the SQL at each step.
The three kinds of integrity a relational database enforces, why redundancy causes anomalies, and where a derived value is worth its maintenance cost.
How to get from a description of a business to a set of tables: find the entities, give them attributes, connect them, and name everything consistentl...
Two tables that both have many of each other need a third table. Learn the junction table pattern, its key design, and how to query and count across i...
The two simplest relationships and the single rule that decides where the foreign key goes - plus when a one to one split is actually worth it.