Skip to content

Latest commit

 

History

History
122 lines (96 loc) · 5.22 KB

File metadata and controls

122 lines (96 loc) · 5.22 KB

5. Functions - SQL Built-in Functions and Operations

Master SQL's powerful built-in functions for string manipulation, numeric calculations, date operations, and data aggregation.

📋 Learning Objectives

By the end of this section, you will be able to:

  • Use string functions for text manipulation and formatting
  • Apply numeric functions for mathematical calculations
  • Work with date/time functions for temporal data analysis
  • Implement aggregate functions for data summarization
  • Combine multiple functions in complex expressions
  • Choose the right function for specific data processing needs

🗂️ Section Contents

📖 Concepts - Learn the Theory

Start here to understand function categories and usage

💻 Examples - See Working Code

Run these examples to see functions in action

🏋️ Exercises - Practice Your Skills

Test your understanding with hands-on problems

📚 Resources - Quick Reference

Handy function references and cheat sheets

🎯 Learning Path

Follow this recommended sequence:

  1. 📖 Read Concepts: Start with String Functions
  2. 💻 Run Examples: Practice with String Examples
  3. 🏋️ Do Exercises: Test yourself with Practice Problems
  4. 📚 Reference: Use Function Reference as needed

🛠️ Prerequisites

⏱️ Estimated Time

4-5 hours to complete all materials

🎯 Key Function Categories

String Functions

  • UPPER()/LOWER() - Change text case
  • SUBSTRING() - Extract parts of strings
  • LENGTH()/LEN() - Get string length
  • CONCAT() - Combine strings
  • TRIM() - Remove whitespace
  • REPLACE() - Replace text patterns

Numeric Functions

  • ROUND() - Round to specified decimals
  • CEILING()/FLOOR() - Round up/down to integers
  • ABS() - Absolute value
  • POWER() - Exponentiation
  • SQRT() - Square root
  • RAND() - Random numbers

Date Functions

  • GETDATE()/NOW() - Current date/time
  • DATEADD() - Add time intervals
  • DATEDIFF() - Calculate time differences
  • YEAR()/MONTH()/DAY() - Extract date parts
  • FORMAT() - Format dates for display

Aggregate Functions

  • COUNT() - Count rows or values
  • SUM() - Add up numeric values
  • AVG() - Calculate averages
  • MIN()/MAX() - Find minimum/maximum values
  • GROUP_CONCAT() - Concatenate grouped values

🚀 Real-World Applications

These functions are essential for:

  • Data Cleaning: Standardizing text, fixing formatting issues
  • Reporting: Formatting output for business reports
  • Analytics: Calculating metrics and KPIs
  • Data Transformation: Converting data between formats
  • User Interface: Displaying data in user-friendly formats

⚠️ Database Differences

While SQL is standardized, function syntax can vary:

Function SQL Server MySQL PostgreSQL Oracle
String Length LEN() LENGTH() LENGTH() LENGTH()
Current Date GETDATE() NOW() NOW() SYSDATE
Substring SUBSTRING() SUBSTRING() SUBSTRING() SUBSTR()
Concatenation + or CONCAT() CONCAT() || or CONCAT() ||

💡 Success Tips

  1. Practice with Real Data: Use actual datasets to understand function impact
  2. Combine Functions: Learn to chain functions for complex operations
  3. Handle NULLs: Understand how functions behave with NULL values
  4. Check Documentation: Function behavior can vary between database versions
  5. Performance Awareness: Some functions can impact query performance

🔄 Navigation

← Previous: Filtering & Conditions | Next: Grouping & Aggregation →


🏠 Back to Main