Get Started

ANY_VALUE

One of the new functions you learned that is specific to GoogleSQL is the ANY_VALUE aggregate that allows you to return a value from a text column. You can use this in combination with HAVING to find a maximum or minimum value. This allows us to have some flexibility to return a single value when aggregating across a large dataset.

This is a part of the course

“Introduction to BigQuery”

View Course

Exercise instructions

  • Complete the query by using the ANY_VALUE aggregate function on the product_category_name_english column, including the HAVING clause to find the maximum value of product_photos_qty, and assign the alias random_product to the result.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Finish the query below by adding the ANY_VALUE function

SELECT
  product_weight_g,
    -- Complete the query by adding the ANY_VALUE function on the product category column
	___
FROM ecommerce.ecomm_products
GROUP BY product_weight_g;
Edit and Run Code

This exercise is part of the course

Introduction to BigQuery

IntermediateSkill Level
4.1+
7 reviews

Unlock BigQuery's power: grasp its fundamentals, execute queries, and optimize workflows for efficient data analysis.

Learn how to query data using common table expressions, aggregations, and window functions.

Exercise 1: Common table expressionsExercise 2: Filtering data with CTEsExercise 3: Optimizing using CTEsExercise 4: Using multiple CTEsExercise 5: AggregationsExercise 6: Classifying aggregate functionsExercise 7: Using COUNTIFExercise 8: Filtering with HAVINGExercise 9: ANY_VALUE
Exercise 10: Special aggregations in BigQueryExercise 11: Logical aggregatesExercise 12: Using STRING_AGG and ARRAY_CONCAT_AGGExercise 13: Approximate statistical functionsExercise 14: WINDOW FunctionsExercise 15: Writing a window queryExercise 16: RANK and LEAD/LAGExercise 17: Using row based WINDOW functionsExercise 18: Filtering with QUALIFY

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free