Calculating Summary Statistics
Statistics reduce a dataset to information users can interpret.
SELECT
COUNT(*) AS result_count,
COUNT(DISTINCT team_name) AS team_count,
SUM(wins) AS total_wins,
AVG(wins) AS average_wins,
MAX(wins) AS highest_wins
FROM team_results;
Choose statistics because they answer a need, not because functions are available. Label values clearly and round averages deliberately.
<p>Average wins:
<?= number_format((float) $stats["average_wins"], 1) ?>
</p>
Interpretation
A number without context is weak. State what population and timeframe it represents. Do not imply cause from a descriptive statistic.
Check
- Each statistic has a purpose.
- Null or empty data is handled.
- Units and labels are visible.
- Rounding is consistent.
- Results are checked manually with a known dataset.