MySQL 分组后查询每组最新的一条数据,并查出每组的总数(适用于主键自增)
SELECT * FROM (select *from pf_module_work t left join pf_module_work_history h on h.work_id = t.work_id WHERE h.id IN ( select max(id) from pf_module_work_history h GROUP BY h.creator //子表根据userId分组,然后查出所有用户的最大的id记录,也就是最新的一条数据的id ) ) a, (SELECT h.creator ,count(h.creator) as commitTimes FROM pf_module_work_history h GROUP BY h.creator) AS b where a.creator = b.creator
1.来写一个长难sql的分析
下班记得打卡