场景:对每种类型的ID值最大的记录进行分组查询。
mysql数据库30W的数据量。
写法1 :
select * from test1 t1 where t1.id in (
selectmax(wxdyc ) as id from test1 t
GROUP BY t.col1
) )
需要30秒以上;
写法2 :
select t2.* from (
selectmax(wxdyc ) as id from test1 t
GROUP BY t.col1
) t1 LEFT JOIN test1 t2 on t1.id=t2.id
时间在0.1秒以下