Trong Postgresql se la nhu the nay:
select b.ma, b.masanpham, b.dongia, b.thoigiancapnhat from
(select thoigiancapnhat from bangtonghop where thoigiancapnhat in (select max(thoigiancapnhat) from bangthonghop group by masanpham,makhachhang)) as a inner join
(select *from bangtonghop) as b on a.thoigiancapnhat = b.thoigiancapnhat;