Examples

Page 33 of 50

Browse code examples

sqlSnippet

Row Number Ties Need Tiebreak

ROW_NUMBER assigns arbitrary order among rows tied on the sort key; add a unique tiebreaker to make numbering, paging, and deduplication reproducible.

sqlSnippet

Sessionize Clicks With Lag

Split event streams into sessions: LAG measures the gap since the previous click, a flag marks 30-minute gaps, and a running SUM assigns session numbers.

sqlSnippet

String Agg Cumulative Window

Build running event trails with string_agg as a window aggregate: ROWS frames accumulate from the partition start or a trailing window of recent steps.

sqlSnippet

Update Top N Per Group Via CTE

Window functions cannot appear in an UPDATE's WHERE clause, so rank rows in a CTE with ROW_NUMBER and flip status through UPDATE FROM past the newest order.

typescriptSnippet

Typed Dialog Element Confirm Flow

Wire a confirm dialog with typed event listeners: cancel is cancelable, close(reason) sets returnValue, and querySelector narrows type and null in one generic.