Write one SQL query that calculates several conditional counts such as passed, failed, and error results.
Answer
Use conditional aggregation: turn each condition into 1 or 0 with CASE and then SUM those values, optionally grouping by build, suite, day or another dimension. This avoids separate queries for every status and makes it easy to reconcile the subtotal counts against the overall row count.
Strong answer includes
- uses SUM with CASE or a dialect-equivalent filtered aggregate
- can add GROUP BY for per-build or per-team metrics
- reconciles conditional totals with the total population
Practical example
Dialect · Portable SQLRuntime · SQLite sample DB
Runs against the resettable SQLite sample database used by the playground.
SQL
Result
Run the query to see the result.
Turn each condition into 1 or 0 and aggregate it. Add GROUP BY to calculate the same metrics per build, suite, team, or day.
Expected result: One row per group with total and per-condition counts.