Aggregating data
You can aggregate data results by fields.
For example:
- Calculate the number of taxi rides.
- Calculate the average tip amount.
- Group by taxi pick-up location (
PULocationID
).
SELECT
PULocationID,
COUNT(*) AS rides_count, -- The COUNT aggregate function returns the number of rows
-- resulting from the query execution.
-- The asterisk (*) indicates that the COUNT function
-- counts the total number of rows in the table.
-- It counts each row separately.
-- The result includes rows that contain null values.
AVG(tip_amount) AS avg_tip_amount
FROM
`tutorial-analytics`
GROUP BY PULocationID -- The column by which the data is aggregated.
Take a look at the example on the right and click
Query results are available in the Result tab as a table or schema.