Actually, the problem doesn't make sense. One can group & count on IP address, as in the following query:
SELECT ipno, COUNT(*)
FROM Weblog
WHERE retcode > 300
GROUP BY ipno
However, suppose that there are two requests from a particular IP but with different return codes (say 350 and 400); the above query will show a count of two for that address, but what does it mean to sort the results by return code when (now that the results have been grouped) there is now no single such code for that one IP address?
MySQL is exceptional in that it permits you to access "hidden" columns (such as retcode
in the above query) without encompassing in an aggregate function; other RDBMS would raise an error with the query you gave in your question. However, for performance reasons MySQL chooses an indeterminate value amongst those in each group for the hidden column so unless they are all the same one should not rely on the results.
Perhaps you want to group on ipno
and retcode
:
SELECT ipno, retcode, COUNT(*)
FROM Weblog
WHERE retcode > 300
GROUP BY ipno, retcode
ORDER BY retcode DESC