I have the balance table, which always when executing a procedure, is generated a new record in the same, being able to have several record the same day ... However, when I make an appointment, I want to bring only the last record of each day, so I did this:
DELIMITER //
CREATE PROCEDURE pro_get_balanco_diario(IN var_data DATETIME)
BEGIN
SELECT *
FROM saldo
WHERE DATE(data_mov_saldo) = var_data
ORDER BY data_mov_saldo DESC
LIMIT 1;
END //
However, I now need to do this query by bringing the data between a date range, ie bringing the data between a start date and an end date, but bringing only the last record for each day, as in the above procedure. / p>
The fields of the tables are shown in the image.