Analyze the last 3 records of a table using PHP

-1

I need some help.

I have a table where in the price field I need to evaluate if the price of the last 3 records were greater than 50. If so I have to display an alert.

Well get the last 3 records I would get using a select with desc and limit 3. If it were submitted for display would be easy the problem is how to evaluate the last 3 records and know if the 3 were greater than 50 or not.

The part of the alert is also easy, I can evaluate the data I give echo.

    
asked by anonymous 28.06.2018 / 22:50

1 answer

0

Create a calculated field in the select that signals whether or not the value is below 50:

select preco,
       if preco < 50 then 'S' else 'N' endif as preco_menor
from tabela
order by data desc limit 3

So you will have the last three prices and each of them signaled if the value is below or not 50 or whatever you want.

    
28.06.2018 / 23:01