MySQL Functions with query
🐬 MySQL Functions
(Beginner → Interview Level)
MySQL provides built-in functions to perform calculations, string handling, date operations, and data analysis directly inside SQL queries.
1️⃣ What are MySQL Functions?
MySQL functions are predefined methods that:
-
Take input values
-
Perform operations
-
Return a single value
👉 Used in SELECT, WHERE, HAVING, ORDER BY, etc.
2️⃣ Types of MySQL Functions
| Category | Examples |
|---|---|
| Aggregate | COUNT(), SUM(), AVG(), MIN(), MAX() |
| String | UPPER(), LOWER(), CONCAT(), LENGTH() |
| Numeric | ABS(), ROUND(), CEIL(), FLOOR() |
| Date/Time | NOW(), CURDATE(), YEAR() |
| Control | IF(), CASE |
3️⃣ Aggregate Functions (Most Important ⭐)
COUNT()
SUM()
AVG()
MIN() / MAX()
4️⃣ String Functions with Queries
UPPER() / LOWER()
CONCAT()
LENGTH()
5️⃣ Numeric Functions
ROUND()
ABS()
CEIL() / FLOOR()
6️⃣ Date & Time Functions ⭐
NOW()
CURDATE()
YEAR(), MONTH(), DAY()
7️⃣ Control Flow Functions
IF()
CASE
8️⃣ Functions in WHERE Clause
9️⃣ Functions with GROUP BY
📌 Interview MCQs (Very Important)
Q1. Which function returns the total number of rows?
A) SUM()
B) COUNT()
C) TOTAL()
D) ROWS()
✅ Answer: B
Q2. Which function converts text to uppercase?
A) UCASE()
B) TOUPPER()
C) UPPER()
D) CAPITAL()
✅ Answer: C
Q3. Which function returns the current date?
A) NOW()
B) CURDATE()
C) DATE()
D) TODAY()
✅ Answer: B
Q4. Which function is used to combine strings?
A) ADD()
B) CONCAT()
C) MERGE()
D) JOIN()
✅ Answer: B
Q5. Which function is used with GROUP BY?
A) WHERE
B) ORDER BY
C) Aggregate functions
D) DISTINCT
✅ Answer: C
Q6. What does AVG() return?
A) Total
B) Maximum
C) Minimum
D) Average
✅ Answer: D
Q7. Which function rounds a number?
A) FLOOR()
B) CEIL()
C) ROUND()
D) FIX()
✅ Answer: C
Q8. Which function checks conditions?
A) IF()
B) CHECK()
C) WHEN()
D) TEST()
✅ Answer: A
🔥 Exam & Interview Tips
✔ Memorize aggregate functions
✔ Practice functions with GROUP BY
✔ Understand CASE vs IF
✔ Functions are heavily used in real queries
✅ Summary
-
MySQL functions simplify data processing
-
Aggregate, String, Numeric, Date functions are crucial
-
Frequently used in SELECT, WHERE, GROUP BY
-
Very important for interviews & exams
