We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

ROUND

Sometimes we need to round some numbers, particularly when working with the results of an aggregation. We can use the ROUND() function to get the job done.

The SQL ROUND() function allows you to specify both the value you wish to round and the degree of precision to be applied:

ROUND(value, precision)

If no precision is given, SQL will round the value to the nearest whole value:

SELECT ROUND(AVG(song_length))
FROM songs;

This query returns the average song_length from the songs table, rounded to the nearest whole number.

If we do provide a precision, SQL will round to that many decimal places:

SELECT ROUND(AVG(song_length), 1)
FROM songs;

The same query, but rounded to a single decimal place.

Assignment