-3
I have a column called data_nasc
and another age column, but wanted every time the system loaded this instruction into Mysql and updated the age field of all records.
So far it works, but the result comes out in the temporary column ColunaCalculoIdade
, I want the result update the age column field
SELECT TIMESTAMPDIFF(YEAR, data_nasc, CURRENT_DATE) AS ColunaCalculoIdade
FROM clientes
Why don’t you create a computed column that will calculate this for you? I commented on this in this question: https://answall.com/questions/514534/para-que-serve-a-structura-data-structures-virtual-no-dbeaver-ou-no-mysql/516720#516720
– Ricardo Pontual
remember that only record at include time will be old at that instant, the next day may already be outdated, a computed column will always calculate at the instant of the query :)
– Ricardo Pontual
Usually no age is recorded in the database. Only the date of birth is enough to deduce age.
– Augusto Vasques
I’ve been looking at the computed column, still very complicated for a beginner, what I want is that when I open the Registration Form the user make a query by age and appear the entries with the searched age or when run the report the age is already updated, as much as I could make the above code.
– Mark Damon
I tried to use it like this: UPDATE clients SET age= SELECT TIMESTAMPDIFF(YEAR, data_nasc, CURRENT_DATE) AS Colunacalculoity FROM clients Just wanted the result of birth date calculation to update my age column.
– Mark Damon