group by 取最新或者最后的一条数据

参考:http://blog.csdn.net/hfsaini/article/details/6675451

或者

SELECT

aud.auditingState,
aud.auditingInfoId
FROM
AuditingInfo aud,
(
SELECT
ah.*
FROM
ApplicationHistory ah,
(
SELECT
auditingInfoId,
MAX(createTime) AS optionTime
FROM
ApplicationHistory
GROUP BY
auditingInfoId
) ai
WHERE
ah.auditingInfoId = ai.auditingInfoId
AND ah.createTime = ai.optionTime
) ahi
WHERE
aud.auditingInfoId = ahi.auditingInfoId
AND aud.auditingState = 17
AND auditingInfoChannel = 1

AND ahi.createTime < '2017-9-26 10:39:10';

或者先排序

SELECT ui.* FROM(SELECT user_id,mobile_phone,login_time FROM credit_app.user_login_record ORDER BY login_time DESC ) ui GROUP BY ui.user_id

你可能感兴趣的:(group by 取最新或者最后的一条数据)