0
0
PostgreSQLquery~10 mins

Numeric and decimal precision in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a column with numeric precision of 5 and scale of 2.

PostgreSQL
CREATE TABLE products (price NUMERIC([1]));
Drag options to blanks, or click blank then click option'
A5, 2
B10, 5
C3, 1
D7, 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one number inside NUMERIC() without scale.
Swapping precision and scale values.
2fill in blank
medium

Complete the code to insert a value with two decimal places into the price column.

PostgreSQL
INSERT INTO products (price) VALUES ([1]);
Drag options to blanks, or click blank then click option'
A99.99
B123.456
C100
D12.3456
Attempts:
3 left
💡 Hint
Common Mistakes
Inserting values with more than two decimal places.
Inserting integer values without decimal places.
3fill in blank
hard

Fix the error in the SELECT statement to round the price to 1 decimal place.

PostgreSQL
SELECT ROUND(price, [1]) FROM products;
Drag options to blanks, or click blank then click option'
A3
B0
C-1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 rounds to whole number, not one decimal place.
Using negative numbers rounds to tens or hundreds.
4fill in blank
hard

Fill both blanks to create a table with a decimal column and insert a value with correct precision.

PostgreSQL
CREATE TABLE sales (amount DECIMAL([1], [2]));
INSERT INTO sales (amount) VALUES (123.45);
Drag options to blanks, or click blank then click option'
A6
B2
C4
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using scale larger than precision.
Choosing precision smaller than number of digits in value.
5fill in blank
hard

Fill all three blanks to select prices rounded to 0 decimal places and filter prices greater than 100.

PostgreSQL
SELECT ROUND(price, [1]) AS rounded_price FROM products WHERE price [2] [3];
Drag options to blanks, or click blank then click option'
A1
B>
C100
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for rounding decimal places.
Using wrong comparison operator in WHERE clause.