lmthu > 21-10-15, 09:04 AM
thucgia > 21-10-15, 12:12 PM
SELECT
gm.hang_id,
gm.ngay_moi_nhat,
tpl.gia as gia_moi
FROM
(
SELECT Max(gia.ngay) AS ngay_moi_nhat, gia.hang_id, hang_id & Day(ngay_moi_nhat) & Month(ngay_moi_nhat) & Year(ngay_moi_nhat) AS ma
FROM gia
GROUP BY gia.hang_id
)
as gm
LEFT JOIN
(
SELECT gia.gia, hang_id & day(ngay) & month(ngay) & year(ngay) AS ma
FROM gia
)
as tpl
ON gm.ma = tpl.ma
hang_id ngay_moi_nhat gia_moi
a 20/10/15 1.5
b 21/10/15 2.5
c 19/10/15 3