MySQL Advanced Functions help perform conditional logic, handle NULL values, convert data types, and generate complex computed results directly within SQL queries. They are widely used in reporting, analytics, and data transformation.
-- Using IF() for conditional output
SELECT name, IF(marks >= 40, 'Pass', 'Fail') AS result
FROM students;
-- CASE statement with multiple conditions
SELECT name,
CASE
WHEN marks >= 75 THEN 'Distinction'
WHEN marks >= 40 THEN 'Pass'
ELSE 'Fail'
END AS grade
FROM students;
-- Handling NULL values using COALESCE
SELECT name, COALESCE(phone, 'Not Provided') AS contact
FROM users;
-- NULLIF converts matching values to NULL
SELECT NULLIF(100, 100) AS result;
-- CAST used for data type conversion
SELECT CAST('2025-01-01' AS DATE) AS converted_date;
-- GROUP_CONCAT merges multiple rows into a single string
SELECT department, GROUP_CONCAT(name)
FROM employees
GROUP BY department;