TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2223 4.19K
โœ… SQL Functions ๐Ÿ“Š๐Ÿง 

SQL functions are built-in operations used to manipulate, calculate, and transform data. They help in summarizing results, formatting values, and applying logic in queries.

1๏ธโƒฃ Aggregate Functions
These return a single result from a group of rows.

โ€ข COUNT() โ€“ Counts rows
SELECT COUNT(*) FROM employees;

โ€ข SUM() โ€“ Adds values
SELECT SUM(salary) FROM employees WHERE department = 'IT';

โ€ข AVG() โ€“ Returns average
SELECT AVG(age) FROM customers;

โ€ข MAX() / MIN() โ€“ Highest or lowest value
SELECT MAX(salary), MIN(salary) FROM employees;

2๏ธโƒฃ String Functions

โ€ข UPPER() / LOWER() โ€“ Change case
SELECT UPPER(name), LOWER(city) FROM customers;

โ€ข CONCAT() โ€“ Join strings
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;

โ€ข SUBSTRING() โ€“ Extract part of a string
SELECT SUBSTRING(name, 1, 3) FROM products;

โ€ข LENGTH() โ€“ Length of string
SELECT LENGTH(description) FROM products;

3๏ธโƒฃ Date Functions

โ€ข CURRENT_DATE / NOW() โ€“ Current date/time
SELECT CURRENT_DATE, NOW();

โ€ข DATE_ADD() / DATE_SUB() โ€“ Add or subtract days
SELECT DATE_ADD(hire_date, INTERVAL 30 DAY) FROM employees;

โ€ข DATEDIFF() โ€“ Difference between dates
SELECT DATEDIFF(end_date, start_date) FROM projects;

โ€ข YEAR() / MONTH() / DAY() โ€“ Extract parts
SELECT YEAR(order_date), MONTH(order_date) FROM orders;

4๏ธโƒฃ Mathematical Functions

โ€ข ROUND() โ€“ Round decimals
SELECT ROUND(price, 2) FROM products;

โ€ข CEIL() / FLOOR() โ€“ Round up/down
SELECT CEIL(4.2), FLOOR(4.8);

โ€ข ABS() โ€“ Absolute value
SELECT ABS(balance) FROM accounts;

5๏ธโƒฃ Conditional Function

โ€ข COALESCE() โ€“ Returns first non-null value
SELECT COALESCE(phone, 'Not Provided') FROM customers;

โ€ข CASE โ€“ If/else logic in SQL
  SELECT name,  
CASE
WHEN salary > 50000 THEN 'High'
WHEN salary BETWEEN 30000 AND 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_band
FROM employees;


๐ŸŽฏ Use These Functions To:
โ€ข Summarize data
โ€ข Clean and format strings
โ€ข Handle nulls
โ€ข Calculate time differences
โ€ข Add logic into queries

๐Ÿ’ฌ Tap โค๏ธ for more!
  • โค 12
  • ๐Ÿ‘ 2
More from @sqlanalyst
  1. Oct 13, 2026SQL Interview Series โ€” Part 8 ๐Ÿ“Œ Question 8: Find Customers Who Have Never Placed an Orderโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 2026SQL Interview Series โ€” Part 6 ๐Ÿ“Œ Question 6: Find the Top 2 Highest-Paid Employees in Eachโ€ฆ
  4. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  5. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  6. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’