FIND YOUR NEXT FEW LINES

Results for “SQL”

Small, practical examples. Search by task or narrow things down below.

500 snippets foundClear filters
PostgresSubqueries & ranked selection

Attach an overall count to every row

Postgres: An uncorrelated scalar subquery supplies the same aggregate to each output row.

Postgres✓ Tested
PostgresConstraints & defaults

Block deletion of a referenced parent

Postgres: The default foreign-key action prevents deletion while a child still refers to the parent.

Postgres✓ Tested
SQLiteJSON data

Build a JSON array from rows

Aggregate ordered text values into JSON.

json_group_array✓ Tested
PostgresSubqueries & ranked selection

Build a query from several named stages

Postgres: Separate row selection from aggregation using two common table expressions.

Postgres✓ Tested
PostgresWindow analytics

Calculate a cumulative integer percentage

Postgres: Divide a running window sum by the complete total using a unique ordering key.

Postgres✓ Tested
PostgresWindows & text

Calculate a running total

Accumulate values in row order.

window✓ Tested
PostgresGetting Started

Calculate a total for each group

Postgres: Group nonmissing categories and calculate separate totals.

Postgres✓ Tested
PostgresGetting Started

Calculate a value with SELECT

Postgres: Evaluate a small arithmetic expression on the database server.

Postgres✓ Tested
PostgresReporting & grouped calculations

Calculate each group’s integer percentage of the total

Postgres: Multiply before division and protect against a zero denominator.

Postgres✓ Tested
PostgresReporting & grouped calculations

Calculate each group’s numeric spread

Postgres: Subtract MIN from MAX to report the difference between extremes.

Postgres✓ Tested
SQLiteDates & time

Calculate whole days between dates

Subtract Julian day values for date-only inputs.

julianday✓ Tested
PostgresJSON & arrays

Check JSONB containment

Test whether an object contains a key-value pair.

jsonb✓ Tested