Anonymised Previous Professional Experience

When SQL Returns the Wrong Answer

Some operational reports depended on several layers of SQL views and calculations. A report could show an incorrect or duplicated value even when every query ran successfully.

Finding the source of the discrepancy meant tracing the value backwards through the calculation chain.

The context

Operational reports combined relational data, derived views and historical records from several sources. The figures depended on how the queries joined, filtered and classified records, and on what the identifiers and values meant in the application.

The investigation

  • Traced displayed values through dependent SQL views.
  • Examined intermediate calculations and aggregations.
  • Investigated joins that could multiply records.
  • Checked filters and historical identifiers.
  • Compared results with the intended business rules.
  • Modified selected queries and views where necessary.
  • Considered the effects on downstream reports.

The difficult part

A valid query can produce an incorrect result. A small change in a source relationship can affect calculations several layers away, so the report that shows a discrepancy may be far removed from the dependency that caused it.

What this experience demonstrates

Investigating complex relational data, reconstructing calculation paths and checking whether the resulting figures reflect the business rules they are meant to represent.