Can you provide an example of a complex SQL query you wrote and explain its purpose?
Use the provided relational tables to produce a representative example. The query should summarize qualifying analyst activity and make the purpose of each major operation clear.
Output
- One row per analyst and dataset with at least two query runs from 2025 onward.
- Return
dataset_name, analyst_name, successful_runs, total_runs, success_rate_pct, latest_success_at, and dataset_rank.
- Rank analysts within each dataset by success rate, then successful runs, descending. Sort by dataset name, rank, and analyst name.
Output details
- Include query runs with
started_at >= DATE '2025-01-01'.
- Count runs with status
success as successful_runs, and count all qualifying runs as total_runs.
- Round
success_rate_pct to exactly 2 decimal places.
- Set
latest_success_at to the latest started_at among runs with status success.
- Use competition ranking for ties, assigning equal
dataset_rank values and leaving rank gaps.
- Sort
dataset_name, dataset_rank, and analyst_name in ascending order.