I want to create chart.js
for avarage age in my company. But I can’t create the query.
SELECT DATEDIFF(CURRENT_DATE, STR_TO_DATE(t.employee_birthday, '%Y-%m-%d'))/365 AS `ageInYears` FROM `employee` `t` WHERE `employee_birthday` BETWEEN `employee_birthday` = 20 and `employee_birthday` = 30
Advertisement
Answer
Presumably, employee_birthday
is actually a date. At last that would make sense to me.
If you want employees between 20 and 30, then the logic is something like this:
WHERE employee_birthday >= CURDATE() - INTERVAL 30 YEAR AND employee_birthday < CURDATE() - INTERVAL 20 YEAR