在mysql查询下面获取错误
无效的组函数使用
SELECT logtime
from sgwebdb.audit_log
where logtime < MAX(logtime)
AND userid = 'admin'
AND activity = 'LOGIN';
最佳答案
请改为:
SELECT logtime
from sgwebdb.audit_log
where logtime < (SELECT MAX(logtime) FROM sgwebdb.audit_log )
AND userid = 'admin'
AND activity = 'LOGIN';
更新
对于第二个最大值,可以执行以下操作:
SELECT logtime
FROM
(
SELECT logtime
FROM sgwebdb.audit_log
WHERE userid = 'admin'
AND activity = 'LOGIN'
ORDER BY logtime DESC
LIMIT 2
) AS t
ORDER BT logtime
LIMIT 1;