FIND YOUR NEXT FEW LINES

The snippet library.

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

10 snippets foundClear filters
SQLiteReporting & grouped calculations

Calculate each group’s integer percentage of the total

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

SQLite✓ Tested
SQLiteReporting & grouped calculations

Calculate each group’s numeric spread

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

SQLite✓ Tested
SQLiteReporting & grouped calculations

Compute an integer weighted average

SQLite: Multiply before summing and guard a zero total weight with NULLIF.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Count distinct values within a result

SQLite: COUNT DISTINCT counts distinct non-null values.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Count rows satisfying separate conditions

SQLite: SUM over CASE expressions calculates several conditional counts in one scan.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Distinguish row count from non-null value count

SQLite: COUNT(*) includes every row while COUNT(column) skips NULL values.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Filter rows before grouping

SQLite: WHERE limits the rows contributing to the aggregate; it differs from filtering completed groups with HAVING.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Group by more than one field

SQLite: Each distinct combination of grouping fields produces its own row.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Return zero for a sum over no rows

SQLite: SUM produces NULL for an empty input; COALESCE supplies the desired reporting default.

SQLite✓ Tested
SQLiteReporting & grouped calculations

Turn known group values into columns

SQLite: Conditional aggregation gives a portable pivot when the category set is known.

SQLite✓ Tested