SELECT *
FROM `_car_emptyweight`
ORDER BY `_car_emptyweight`.date_modified DESC
ผมลองใช้ group by กับ having แล้วแต่ก็ยังไม่ได้ ไม่แน่ใจต้องเขียนsqlยังไง ช่วยดูให้หน่อยครับ
อยากให้แสดง car_emptyweight เป็น 11111 ไม่ใช่ 10000 อ่าครับ
่
Code (PHP)
SELECT *
FROM `_car_emptyweight`
GROUP BY `_car_emptyweight`.car_id
HAVING MAX(`_car_emptyweight`.date_modified)
ORDER BY `_car_emptyweight`.date_modified
select
m_car_id,
(select car_empty_weight from _car_emptyweight where car_id = m_car_id
and date_modified = m_date_modified) as car_empty_weight,
m_date_modified
from (
select car_id as m_car_id,
max(date_modified) as m_date_modified
from _car_emptyweight
group by car_id
) as t;
SELECT `_car_emptyweight`.*
FROM `_car_emptyweight`,
(SELECT car_id, MAX(date_modified) AS mxd FROM `_car_emptyweight`
GROUP BY car_id) as g
WHERE `_car_emptyweight`.car_id = `g`.car_id and `_car_emptyweight`.date_modified = `g`.mxd
ORDER BY `_car_emptyweight`.car_id