select join_id,max(cardindex) cardindex from mealrecords group by join_id) n on m.join_id=n.join_id and m.cardindex=n.cardindex inner join employee e on m.join_id=e.join_id left join departs d on e.depart_id=d.depart_id
查询卡余额
select m.join_id, m.cardbalance,e.emp_id,e.emp_fname,d.depart_name from mealrecords m inner join (
select join_id,max(cardindex) cardindex from mealrecords group by join_id) n on m.join_id=n.join_id and m.cardindex=n.cardindex inner join employee e on m.join_id=e.join_id left join departs d on e.depart_id=d.depart_id
select join_id,max(cardindex) cardindex from mealrecords group by join_id) n on m.join_id=n.join_id and m.cardindex=n.cardindex inner join employee e on m.join_id=e.join_id left join departs d on e.depart_id=d.depart_id