Show each team's share of total GPU hours with a window over all rows
Why it matters Cost and capacity reports always show share of total next to raw totals.
A shared GPU cluster report shows each team's hours and its share of the total, so it is clear who uses the most compute.
Write query() returning a SQLite SQL string. Table jobs(job_id INTEGER, team TEXT, gpu_hours INTEGER), integer hours.
Return one row per team: (team, hours, pct) where hours = SUM(gpu_hours) for the team and pct = ROUND(100.0 * hours / total, 1), total being the sum over all jobs. Order by hours descending, then team ascending.
def query()Example
team 'nlp' 6 + 1 hours, team 'cv' 3 hours give [('nlp', 7, 70.0), ('cv', 3, 30.0)].
Understand the idea
A window function computes a value across a set of rows without collapsing them. OVER () with nothing inside means the window is the whole result. After GROUP BY, you can even window over an aggregate: SUM(SUM(x)) OVER () is the sum of the per-group sums.
Worked example: nlp has 6 + 1 = 7 hours, cv has 3. The grand total is 10. Shares are 100.0 * 7 / 10 = 70.0 and 100.0 * 3 / 10 = 30.0.
Rule: pct = 100.0 * group_total / SUM(group_total) OVER (). In SQLite, INTEGER / INTEGER rounds toward zero, so write 100.0 to force real numbers.
Used in GPU usage reports, token spend by team, and traffic share by model.