Formatting Numbers and Text with FORMAT, LPAD, and RPAD in MySQL
📖 Scenario: You work in a small retail store's database team. You need to prepare product price and code data so it looks neat and consistent for reports and invoices.
🎯 Goal: Build SQL queries that format prices with commas and decimals, and pad product codes with zeros or spaces to a fixed length.
📋 What You'll Learn
Create a table called
products with columns product_id, product_code, and price.Insert 3 products with specific
product_code and price values.Write a query using
FORMAT to display prices with 2 decimal places and commas.Write queries using
LPAD and RPAD to pad product_code to length 8.💡 Why This Matters
🌍 Real World
Formatting numbers and codes is common in reports, invoices, and user interfaces to improve readability and consistency.
💼 Career
Database developers and analysts often need to format query results for business reports and data exports.
Progress0 / 4 steps