You can try the turnkey solution.
For example. Watch out for one variable called emp_over_80. Whenever you add an employee over this age, emp_over_80 ++. When you delete one, emp_over_80--
At the beginning of each day, run a query to determine the value of emp_over_80 (this may be the employeeโs birthday). Then during the day, you can refer to emp_over_80 instead of re-running the SQL query.
Other options would be to keep the employee table sorted by age. If the last employee is over 80, then your query will return at least one row.
Now many can say that these are terrible coding methods, and I agree with them. But I donโt see another way to find out the magic result (even partial result) of the request before it starts.
Perry horwich
source share