■ SQL Functions (Notes with Syntax & Outputs)
■ Aggregate Functions
Function Description Syntax Output (Example)
COUNT() Counts number of rows SELECT COUNT(*) FROM Students; 5
SUM() Calculates total sum SELECT SUM(Age) FROM Students; 102
AVG() Calculates average value SELECT AVG(Age) FROM Students; 20.4
MIN() Finds minimum value SELECT MIN(Age) FROM Students; 18
MAX() Finds maximum value SELECT MAX(Age) FROM Students; 25
■ String Functions
Function Description Syntax Output (Example)
LEN() Length of string SELECT LEN('Hello'); 5
UPPER() Converts to uppercase SELECT UPPER('sql'); SQL
LOWER() Converts to lowercase SELECT LOWER('SQL'); sql
SUBSTRING() Extracts substring SELECT SUBSTRING('Database',1,4); Data
REPLACE() Replaces part of string SELECT REPLACE('banana','na','xy'); baxyxy
LTRIM() Removes left spaces SELECT LTRIM(' SQL'); SQL
RTRIM() Removes right spaces SELECT RTRIM('SQL '); SQL
■ Date & Time Functions
Function Description Syntax Output (Example)
GETDATE() Current date & time SELECT GETDATE(); 2025-09-10 19:20:30
DATEADD() Adds interval SELECT DATEADD(YEAR,1,'2025-01-01'); 2026-01-01
DATEDIFF() Difference in units SELECT DATEDIFF(DAY,'2025-01-01','2025-01-05'); 4
DAY() Extracts day SELECT DAY('2025-09-10'); 10
MONTH() Extracts month SELECT MONTH('2025-09-10'); 9
YEAR() Extracts year SELECT YEAR('2025-09-10'); 2025
■ Math Functions
Function Description Syntax Output (Example)
ABS() Absolute value SELECT ABS(-15); 15
ROUND() Rounds value SELECT ROUND(123.456,2); 123.46
CEILING() Rounds up SELECT CEILING(10.2); 11
FLOOR() Rounds down SELECT FLOOR(10.8); 10
POWER() Power of number SELECT POWER(2,3); 8
SQRT() Square root SELECT SQRT(16); 4