HAVING
-clause GROUPS, . , , "" - DOES HAVING
, MAX (log_time) log_time (, , HAVING MAX(log_time)
true). , )...
, SELECT
log_time, :
SELECT MAX(log_time), user
FROM logs
WHERE action = "Processed"
GROUP BY action;
, "1" , , GROUP BY. , MySQL , . 4 . , :
SELECT logs.user, logs.log_time
FROM logs INNER JOIN
(SELECT MAX(log_time) as max, action
FROM logs
WHERE action = "Processed"
GROUP BY action) sub ON logs.log_time = sub.max AND logs.action = sub.action
NOTE : The SQL query that you give as an example is not a valid SQL query according to standard SQL. It runs on mysql, but this is due to how MySQL implemented GROUP BY. In standard SQL, the only thing you can choose is the results of the aggregate functions and / or columns mentioned in the GROUP BY clause.
So, in other database systems you cannot select user
-column, since it is not GROUP BY
-column, and not the result of an aggregate function. In order for it to be valid standard SQL, you need to write:
SELECT MAX(log_time), user
FROM logs
WHERE action = "Processed"
GROUP BY action, user
;