NiVO / BY TECHNOGISGermany · Indonesia
Summary statistics tutorial

SQLite AVG and NULL: State the Denominator in a Drone Review Summary

Compare an average over supplied values with a deliberately zero-filled average, preserving missing observations and recorded zeroes in an invented drone review register.

SQLite AVG and NULL: State the Denominator in a Drone Review Summary

Ask what the average actually includes

A drone delivery review may summarize durations recorded in a small handoff register. Some records may contain a supplied zero, while another has no known duration. An average can change when the missing value is replaced with zero even though none of the supplied observations changed. Before comparing two summaries, identify their denominators. This tutorial uses invented durations in seconds to compare SQLite AVG with a deliberately zero-filled expression. It does not measure NiVO processing time, inspect a customer register or establish a productivity benchmark. The exercise concerns the meaning of a summary rather than the speed of an actual workflow.

Write down whether the intended quantity is an average of known observations or an average under an explicit replacement rule. Those are different questions. A recorded zero is part of the supplied data; NULL records the absence of a value in this local example. Keep the total number of rows and the number with known values next to the result. A reader can then see whether a reported number summarizes the whole register or only its observed subset. The missing value still needs a project-specific explanation, which an arithmetic function cannot recover from the other records.

Read AVG and replacement semantics together

SQLite documents AVG as the average of non-NULL inputs. It returns a floating-point result when at least one non-NULL input exists, and NULL when none exists. COUNT of a column counts its non-NULL values, while COUNT star counts rows. The COALESCE function returns its first non-NULL argument, so COALESCE of a missing duration and zero supplies zero to the average. This changes the input population of the expression. It does not discover the missing observation. The example prints both averages explicitly so a replacement rule cannot pass unnoticed as an ordinary reading of the source register.

The helper below accepts only bounded nonnegative integer seconds or None. That narrow profile avoids text, binary data, unit mixtures and ambiguous numeric strings. SQLite can interpret nonnumeric text or binary inputs as zero inside AVG, so accepting arbitrary values without a schema check can create another source of confusion. Rejecting them here is an intentional teaching choice, not a complete validation policy for a real database. If a supplied register permits fractional seconds or another unit, document that contract and adapt the input profile before comparing its results with this small example.

NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips
NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Run the two averages without opening a project database

This Python standard library function creates an in-memory SQLite table, inserts a copy of the supplied values and returns one aggregate row. It reports row count, known count, sum of known values and both averages. The connection closes afterward. The input limit and one-hour bound keep the constructed fixture small; they are not a product specification, database capacity limit or recommended review-duration range. No project file is opened or changed. The zero-filled expression is included for comparison only. It is not presented as a correction to apply automatically when an observation is unavailable.

import sqlite3

def compare_averages(values):
    if not isinstance(values, (list, tuple)) or len(values) > 64:
        raise ValueError("expected at most 64 teaching observations")
    for value in values:
        if value is not None and (type(value) is not int or not 0 <= value <= 3600):
            raise ValueError("expected integer seconds or None in this profile")
    con = sqlite3.connect(":memory:")
    try:
        con.execute("CREATE TABLE observations(seconds INTEGER)")
        con.executemany("INSERT INTO observations VALUES (?)", [(v,) for v in values])
        row = con.execute(
            "SELECT COUNT(*), COUNT(seconds), SUM(seconds), AVG(seconds), "
            "AVG(COALESCE(seconds, 0)) FROM observations").fetchone()
        return dict(zip(["rows", "known", "sum_known_seconds", "avg_known_seconds",
                         "avg_zero_filled_seconds"], row))
    finally:
        con.close()

observations = [10, None, 20, 0]
print(compare_averages(observations))

Check the denominator with the constructed values

The example reports four rows, three known values and a known sum of thirty seconds. AVG of the supplied values is ten seconds because it divides that sum across ten, twenty and zero. The deliberately zero-filled average is seven and a half seconds because the previously unknown observation now contributes zero as a fourth input. The lower result is not evidence that the work became faster. It follows from a changed expression over the same invented register. Keep the expression and its denominator with the displayed number when explaining the difference to another reviewer.

Remove the missing observation and both averages become ten seconds. Remove the supplied zero as well and the known average becomes fifteen seconds. These small variations help distinguish a zero measurement from a missing observation. A report that drops zeroes because they look uninformative changes its population again. Do not silently filter them during an average check. If a project treats some zeroes as error codes, that meaning must be established from the actual schema and producer documentation. The numerical value alone cannot tell this function whether a zero is a valid observation or a special marker.

Test unknown-only and empty inputs separately

For two unknown observations, the result has two rows, zero known values and a NULL known average. The zero-filled expression produces zero because it receives two replacement zeroes. For an entirely empty input, both averages are NULL: there is no row on which COALESCE could supply a replacement. The row count distinguishes those situations. A blank average alone would not show whether a register was empty or contained records with unavailable durations. Retain these states in the output instead of formatting every unavailable result as zero merely to fill a dashboard cell.

The small helper also leaves repeated values intact. Two identical durations can be two separate observations, and an average should not become an average of distinct values unless that is the intended quantity. Similarly, this example has no weights, timestamps or grouping keys. It does not calculate an average by mission, elapsed calendar time or another population absent from the input. If a real summary needs those distinctions, preserve the relevant fields and define the aggregation explicitly. Comparing the same arithmetic formula on different record selections can still produce a misleading comparison.

Hand off the statistic with its missing-data policy

For a real review, retain the file or database revision, units, selected population, row count, known count and exact aggregate expression. State whether unavailable values were excluded, replaced or handled through another agreed rule. Keep sensitive observations in their established project location, and use a constructed fixture when explaining the calculation publicly. If the reporting rule changes, compare both definitions on the same unchanged input before interpreting a numerical difference as progress. A reproducible mean describes the accepted inputs under a stated policy; it does not certify their accuracy or justify a missing-data assumption.

The NiVO catalogue photograph provides aircraft context only. It is not evidence of the invented durations or an actual processing benchmark. The practical result is a summary whose denominator is visible: three supplied values average to ten seconds, while four inputs under a zero-replacement rule average to seven and a half. Keeping those meanings separate lets a drone handoff team discuss the real question behind a changed statistic. The team can then investigate unavailable records and review the underlying workflow without having overwritten unknown information to obtain a convenient number.

Technical references

  1. SQLite aggregate functions: AVG, COUNT and SUM ↗
  2. SQLite scalar functions: COALESCE ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team