Using Mathematical Functions in PostgreSQL
📖 Scenario: You work in a retail company database. You have a table of product prices with decimal values. You want to practice using PostgreSQL mathematical functions to round prices, find ceiling and floor values, and get absolute values for discounts.
🎯 Goal: Build SQL queries step-by-step that use the ROUND, CEIL, FLOOR, and ABS functions on a sample products table.
📋 What You'll Learn
Create a
products table with columns product_id (integer) and price (numeric).Insert exact product prices with decimal values.
Write a query using
ROUND(price, 1) to round prices to 1 decimal place.Write a query using
CEIL(price) to get the smallest integer greater than or equal to the price.Write a query using
FLOOR(price) to get the largest integer less than or equal to the price.Write a query using
ABS(discount) to get the absolute value of discounts.💡 Why This Matters
🌍 Real World
Retail and sales databases often require rounding prices for display, calculating ceilings and floors for pricing tiers, and handling discounts as absolute values.
💼 Career
Knowing how to use mathematical functions in SQL is essential for data analysts and database developers to prepare clean and accurate reports.
Progress0 / 4 steps