Home › Learn › SQL › Aggregates

ROUND and other functions

Lesson 15 of 26. Tidy numbers and text in the result.

ROUND(value, 2) rounds to two decimals, which averages usually need. Other everyday functions: UPPER and LOWER for text case, LENGTH for text length, SUBSTR(text, start, length) for part of a string, ABS, and COALESCE(a, b) which returns the first non-NULL argument (the standard way to replace NULL with a default).

Functions can wrap aggregates: ROUND(AVG(price), 2). They can also appear in WHERE and ORDER BY.

SELECT UPPER(name), COALESCE(city, 'unknown') FROM customers;

Your task

Show each product category with its average price rounded to two decimals.

Hint 1

ROUND(AVG(price), 2)

Show the solution
SELECT category, ROUND(AVG(price), 2) FROM products GROUP BY category;

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.