I'm doing some SQL exercises and I'm not sure if the solution is right, I leave you the statement and the solution.
Surname, Name, age and number of children of employees who are over 50 years old and have children. Result:
SELECT NOMBRE, TRUNC(MONTHS_BETWEEN(SYSDATE, FNACIMIENTO)/12) AS EDAD, HIJOS FROM N_EMPLEADOS WHERE TRUNC(MONTHS_BETWEEN(SYSDATE, FNACIMIENTO)/12) > 50 AND HIJOS > 0;
Where I have the doubt is that if the way of calculating the age is correct, FNACIMINETO is of type date:
TRUNC(MONTHS_BETWEEN(SYSDATE, FNACIMIENTO)/12) AS EDAD
The MONTHS_BETWEEN obtains a decimal number with the number of months and to calculate the year there is /12. This would be fine because it returns a decimal.
Then the TRUNC returns an integer. For example 12.7 years, I would leave you 12.
You can see more info at: Month_Between -> https://www.w3resource.com/oracle/datetime-functions/oracle-months_between-function.php Trunc -> https://docs.oracle.com/cd/B19306_01/server .102/b14200/functions200.htm