Aggregating cycling data
Using native aggregate functions.
An aggregate function operates on a set of rows. The aggregate function receives values for each row and returns one value for all of the rows.
This section shows queries that use the aggregate functions. Each query is followed by the returned output.
This query uses the AVG function to return the average team racing time:
SELECT AVG(cyclist_time_sec) AS Average FROM cycling.team_average WHERE team_name = 'UnitedHealthCare Pro Cycling Womens Team';
average
---------
11474
(1 rows)This query uses the COUNT function to return the number of cyclists in the
specified team:
SELECT COUNT(cyclist_name) AS Row_Count FROM cycling.team_average WHERE team_name = 'UnitedHealthCare Pro Cycling Womens Team';
row_count
-----------
3
(1 rows)This query uses the MIN function to return the fastest team racing
time:
SELECT MIN(cyclist_time_sec) AS Fastest FROM cycling.team_average WHERE team_name = 'UnitedHealthCare Pro Cycling Womens Team';
fastest
---------
11449
(1 rows)This query uses the MAX function to return the slowest team racing
time:
SELECT MAX(cyclist_time_sec) AS Slowest FROM cycling.team_average WHERE team_name = 'UnitedHealthCare Pro Cycling Womens Team';
slowest
---------
11490
(1 rows)This query uses the SUM function to return the total team racing
times:
SELECT SUM(cyclist_time_sec) AS Total_Time FROM cycling.team_average WHERE team_name = 'UnitedHealthCare Pro Cycling Womens Team';
total_time
------------
34424
(1 rows)