
SQL code examples
Browse 251 SQL code examples across 26 topics, including projection and filtering, text search, text formatting.
Jump to a topic
Projection and filtering
Text search
Text formatting
Numeric expressions
Conditional values
Aggregate metrics
Grouping
Sorting and paging
Joins
Subqueries
- Compare to the overall average
- Compare to each queue average
- Find queues with waiting work
- Find queues with no completed jobs
- Count jobs in a scalar subquery
- Find each queue's first job
- Select jobs owned by a team
- Average queue totals
- Find the runner-up distinct duration
- Filter by a multi-column subquery
Window functions
Window frames
- Calculate a running duration
- Take a three-job moving average
- Count remaining jobs
- Count previous jobs only
- Compare to a neighbouring job
- Compute a queue subtotal alongside rows
- Calculate a share of queue duration
- Reuse a window definition
- Exclude the current observation
- Return the first two jobs per queue
Set operations
Calendar operations
Recursive queries
JSON extraction
JSON construction
Writing rows
Constraints and defaults
Upserts and transactions
Schema inspection
Indexes and views
Common table expressions
Data cleaning
Reporting patterns
- Find unfinished work by owner
- Count jobs per active day
- Find the busiest calendar day
- Compare consecutive daily totals
- Compute hours between submissions
- Find a queue's latest status
- Estimate total measured seconds per owner
- Identify queues above a workload share
- List missing queue-day combinations
- Display a summary and detail together