Unlock the power of your data in the cloud! Get hands-on with Google Cloud's core data services like BigQuery and Looker to validate your practical skills in data ingestion, analysis, and management, and earn your Associate Data Practitioner certification!
Prepare and test your skills
Prepare and test your skills
Worked example. The correct answer is already marked and every option is explained below, so there is nothing to select here. To answer questions yourself, start the free trial.
A data analyst is writing a SQL query in BigQuery to analyze bike rental trends. The goal is to generate a report showing the average trip duration broken down by subscriber type and the starting hour of the day.
The analyst writes the following query in BigQuery Studio:
SELECT
subscriber_type,
EXTRACT(HOUR FROM start_time) AS hour_of_day,
AVG(duration_minutes) AS avg_trip_length
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips`
When running the query, BigQuery returns an error indicating that subscriber_type is neither grouped nor aggregated.
Which clause should the analyst append to the query to resolve the error and produce the desired summary report?
GROUP BY clause isIn standard SQL and GoogleSQL for BigQuery, the GROUP BY clause groups rows that share identical values in specified summary columns into summary rows. When aggregate functions such as AVG(), COUNT(), or SUM() are used alongside non-aggregated columns or expressions in a SELECT list, all non-aggregated columns must be included in the GROUP BY clause.
subscriber_type and EXTRACT(HOUR FROM start_time) AS hour_of_day without aggregating them. Adding GROUP BY subscriber_type, hour_of_day informs BigQuery to group records by these unique attribute combinations.AVG() calculation (✓): Once grouped, the AVG(duration_minutes) function calculates the mean trip duration for each distinct combination of subscriber type and hour.SELECT list (such as hour_of_day) as well as the original column references.EXTRACT() and FORMAT_TIMESTAMP().The GROUP BY clause is the standard, syntactically required mechanism in BigQuery SQL to perform grouping transformations before evaluating aggregate functions.
Keep the momentum going with these hand-picked practice scenarios
Want more questions like this?
Get a free certification question every week.