Mysql
 sql >> Database >  >> RDS >> Mysql

Confrontare i valori in MySQL in base al timestamp e identificare le tendenze

Puoi utilizzare una sottoquery correlata per cercare il valore precedente.

SELECT
     *,
     (SELECT lookup.value
        FROM yourTable  AS lookup
       WHERE lookup.id_indicator = yourTable.id_indicator
         AND lookup.date_data < yourTable.date_data
    ORDER BY lookup.date_data DESC
       LIMIT 1
     )   AS previous_value
FROM
    yourTable