group by 取每组最新的一条

单表操作

select mac(a),b,max(time) from test group by b;

多表关联group by 取每组最新一条

select max(a.b_id),max(a.title), max(t.name), max(t.price) from a 
inner join (select * from b order by id, price ) t on t.id = a.b_id 
group by a.b_id;

猜你喜欢

转载自blog.csdn.net/x15270772831/article/details/82343717