Using ABS and MOD Functions in SQL
📖 Scenario: You are working with a sales database that tracks daily sales amounts, including some negative values representing returns. You want to analyze the absolute sales values and find which sales amounts are even or odd.
🎯 Goal: Build SQL queries that use the ABS function to get absolute values of sales amounts and the MOD function to find even or odd sales amounts.
📋 What You'll Learn
Create a table called
daily_sales with columns sale_id (integer) and amount (integer).Insert the exact sales data with negative and positive amounts.
Write a query to select
sale_id and the absolute value of amount using ABS.Write a query to select
sale_id and amount where the amount is even using MOD.💡 Why This Matters
🌍 Real World
Businesses often need to analyze sales data including returns (negative values) and categorize sales amounts as even or odd for reporting or processing.
💼 Career
Knowing how to use ABS and MOD functions in SQL helps database analysts and developers clean and analyze numeric data efficiently.
Progress0 / 4 steps