1 方法
1.1 先筛选 出最新的时间
找出你需要的关键的东西,然后再围绕他进行操作。
-- group时,select 后可以有两种字段:
-- 一种是group by 字段,相当于分组编号;
-- 一种是 各个字段的聚合函数,因为group by 相当于处理每组字段,返回一组唯一值
select appuuid, max(logtime) as logtime from mfal_applicationlog group by appuuid
1.2 然后,再连表查询。
把上面的结果,看作一个表,关联其他表查询。
SELECT app.uuid, app.sn,log.username as lastOperatorName, app.status,app.requestorname,app.createdate, app.updatetime
FROM (select appuuid, max(logtime) as logtime from mfal_applicationlog group by appuuid) as xx
left join mfal_application as app on app.uuid = xx.appuuid
left join mfal_applicationlog as log on log.logtime = xx.logtime
where app.status in ( 1 , 3 , 4 )