Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Query Testing | Query Engine Basics
/
BigQuery Fundamentals

bookChallenge: Query Testing

Desliza para mostrar el menú

Validate calculated totals in a query by checking whether the recorded total amount matches what it should be based on quantity and unit price. The focus is on identifying incorrect records by recalculating the expected total and filtering for mismatches. The end goal is to return only the rows where the stored total is wrong, helping ensure data accuracy in transactional datasets.

The query is expected to return three specific rows, which represent records where the totals do not align correctly.

The core validation logic is:

Quantity×Unit Price=Correct Total\text{Quantity} × \text{Unit Price} = \text{Correct Total}

Compare this calculated value against the existing Total Amount column.

A new calculated column is created to represent the correct total (quantity multiplied by unit price). This makes the comparison explicit and easier to reason about.

The query then filters results to include only rows where:

Total AmountQuantity×Unit Price\text{Total Amount} ≠ \text{Quantity} × \text{Unit Price}

This approach allows you to:

  • Identify incorrect or inconsistent transactional records;
  • Debug pricing or data-entry issues;
  • Validate business logic directly within SQL rather than externally.

The challenge being solved is not about aggregations, but about row-level validation, ensuring each transaction is internally consistent.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 8

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 2. Capítulo 8
some-alt