# Querying Data for a User Need

A query is meaningful when it answers a user question. Begin with the need, then choose fields, filters, calculations and order.

## Example need

A participant wants to find the strongest fictional teams and inspect their performance.

~~~sql
SELECT team_name,
       SUM(wins) AS total_wins,
       SUM(losses) AS total_losses
FROM team_results
GROUP BY team_name
ORDER BY total_wins DESC, team_name ASC;
~~~

This processes many stored rows into one summary per team. It is stronger evidence of processing than simply displaying the imported table.

## Plan the output

Document:

- user and question
- required source fields
- processing or calculation
- useful order/filter
- output form
- success criterion supported

## Check

- [ ] The query answers a stated need.
- [ ] Only required fields are used.
- [ ] Grouping and calculations are correct.
- [ ] Empty results are handled.
- [ ] Output can be tested against known fictional data.