SELECT
sos_wait.order_id,
TIMESTAMPDIFF(MINUTE, sos_wait.created_at , sos_done.created_at)
FROM
sales_order_status_history sos_wait
LEFT JOIN sales_order_status_history sos_done ON sos_wait.order_id = sos_done.order_id
WHERE
sos_wait.created_at > DATE_SUB(NOW(), INTERVAL 90 DAY)
and sos_wait.status = 'doi_thanh_toan' and sos_done.status = 'da_thanh_toan'
GROUP BY
sos_wait.order_id