Search code examples
mysqlgroup-concat

Determine age of items in group_concat MySQL


Is it possible, in a query, to determine age from dates contained inside a group_concat? Perhaps combining the following?

group_concat(children.age)

TIMESTAMPDIFF(YEAR, age, CURDATE())

Or do I need to handle in PHP?


Solution

  • The following code works on my table where id is an INT and age is a DATE:

    SELECT id, group_concat(TIMESTAMPDIFF(YEAR,age, CURDATE())) FROM test4
    group by id