ComeçarComece de graça

Applying aggregate functions to converted values

As demonstrated in the video exercise, converting a column's value from TEXT to a number allows for calculations to be performed using aggregation functions. The summons_number is of type TEXT in the parking_violation dataset. The maximum (using MAX(summons_number)) and minimum (using MIN(summons_number)) of the TEXT representation summons_number can be calculated. If you, however, want to know the size of the range (max - min) of summon_number values , this calculation is not possible because the operation of subtraction on TEXT types is not defined. First, converting summons_number to a BIGINT will resolve this problem.

In this exercise, you will calculate the size of the range of summons_number values as the difference between the maximum and minimum summons_number.

Este exercício faz parte do curso

Cleaning Data in PostgreSQL Databases

Ver curso

Instruções do exercício

  • Define the range_size for summons_number as the difference between the maximum summons_number and the minimum of the summons_number using the summons_number column after converting to the BIGINT type.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

SELECT
  -- Define the range_size from the max and min summons number
  ___(___) - ___(___) AS ___
FROM
  parking_violation;
Editar e executar o código