อันนี้คือโค้ดที่ ใส่ where ac_id เพื่อแยกข้อมูลตามรหัสคะ ผลออกตามรูป
select m.* from transaction as m inner join ( select `date_in`, max(`transaction_id`) mv from transaction group by `date_in` ) mt on m.`date_in` = mt.`date_in` and m.`transaction_id`=mt.mv WHERE ac_id='611190001'
select m.* from transaction as m
inner join (
select ac_id, `date_in`, max(`transaction_id`) mv
from transaction WHERE ac_id='611190001'
group by `date_in`
) mt on m.ac_id=mt.ac_id and m.`date_in` = mt.`date_in` and m.`transaction_id`=mt.mv
หรือ
Code (SQL)
select m.* from transaction as m
inner join (
select ac_id, `date_in`, max(`transaction_id`) mv
from transaction
group by ac_id, `date_in`
) mt on m.ac_id=mt.ac_id and m.`date_in` = mt.`date_in` and m.`transaction_id`=mt.mv
WHERE m.ac_id='611190001'