I need to write a FLOOR clause in my code to convert this piece of code from a function in which uses a bdate column to workout the age of every employee to finding the median age in the table.
DELIMITER \\
DROP FUNCTION IF EXISTS getAge;
CREATE FUNCTION getAge(pdate DATE) RETURNS int(11)
BEGIN
DECLARE years INT;
DECLARE months INT;
DECLARE days INT;
DECLARE age INT;
SELECT YEAR(pdate) INTO years;
SELECT MONTH(pdate) INTO months;
SELECT DAY(pdate) INTO days;
IF ( MONTH(CURRENT_DATE()) > months ) THEN
SELECT ( YEAR(CURRENT_DATE()) - YEAR(pdate) ) INTO age;
ELSEIF ( MONTH(CURRENT_DATE()) < months ) THEN
SELECT ( ( YEAR(CURRENT_DATE()) - YEAR(pdate) ) -1 ) INTO age;
ELSE
IF ( DAY(CURRENT_DATE()) >= DAY(pdate) ) THEN
SELECT ( YEAR(CURRENT_DATE()) - YEAR(pdate) ) INTO age;
ELSE
SELECT ( ( YEAR(CURRENT_DATE()) - YEAR(pdate) ) -1 ) INTO age;
END IF;
END IF;
RETURN age;
END \\
DELIMITER ;
SELECT getAge(bdate)
FROM employee