Can I create a table in mysql that shows the person's age by subtracting today's year - the year it was born?

0

Question: Can I create a table in mysql that shows the age of the person by subtracting the year from today minus the year of birth?

   create table idade2 (ID auto_increment Primary key, data_nasc date, idade int as ((year(curdate() - year(data_nasc)) stored);

Can it be this way?

    
asked by anonymous 12.08.2018 / 23:11

1 answer

0

It would be best if you bring the age in SELECT as follows:

SELECT YEAR(CURRENT_TIMESTAMP) - YEAR(data_nasc) - (RIGHT(CURRENT_TIMESTAMP, 5) < RIGHT(data_nasc, 5)) as idade
  FROM TABELA

It is not very good to save calculation attributes to tables unless you have to do so.

    
12.08.2018 / 23:37