CREATE TABLE client_balance
(
id SMALLINT AUTO_INCREMENT,
id_client INTEGER,
balance_date_start DATETIME,
balance_start INTEGER,
balance_date_mid DATETIME,
balance_mid INTEGER,
PRIMARY KEY (id)
);
SELECT cb.*,
DATEDIFF(cb.balance_date_mid, cb.balance_date_start) AS diff
FROM client_balance AS cb
GROUP BY cb.id_client
HAVING MAX(diff);