ROUNDing
In the last chapter, you solved the task and received a number with many digits after the decimal place. This is surely precise, but not representative, as there is no way to pay 0.002$, for example. It would be great if we could round numbers to some digits.
Surely it's also implemented into SQL! To round number to n
decimal places use ROUND(column_name, n)
function. For example, from our audi_cars
dataset let's calculate the average price of TT model cars with mileage less than 3000 and round the result to 0 decimals (so it will be an integer).
123SELECT ROUND(AVG(price), 0) FROM audi_cars WHERE model = 'TT' AND mileage < 3000
That's more representative!
Swipe to start coding
From the audi_cars
table calculate the average price for Petrol cars (column fueltype
) with Semi-Auto transmission (column transmission
). Round the result to 2 digits after the comma.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Resumir este capítulo
Explicar el código en file
Explicar por qué file no resuelve la tarea
Awesome!
Completion rate improved to 2.63
ROUNDing
Desliza para mostrar el menú
In the last chapter, you solved the task and received a number with many digits after the decimal place. This is surely precise, but not representative, as there is no way to pay 0.002$, for example. It would be great if we could round numbers to some digits.
Surely it's also implemented into SQL! To round number to n
decimal places use ROUND(column_name, n)
function. For example, from our audi_cars
dataset let's calculate the average price of TT model cars with mileage less than 3000 and round the result to 0 decimals (so it will be an integer).
123SELECT ROUND(AVG(price), 0) FROM audi_cars WHERE model = 'TT' AND mileage < 3000
That's more representative!
Swipe to start coding
From the audi_cars
table calculate the average price for Petrol cars (column fueltype
) with Semi-Auto transmission (column transmission
). Round the result to 2 digits after the comma.
Solución
¡Gracias por tus comentarios!
Awesome!
Completion rate improved to 2.63single