I have a system that logs errors. Selection from my errortable:
SELECT message, personid, count(*)
FROM errorlog
WHERE time BETWEEN TO_DATE(foo) AND TO_DATE(foo) AND substr(message,0,3) = 'ERR'
GROUP BY personid, message
ORDER BY 3
What I want is to see if any user is “producing” more errors then others. For instance ERROR FOO, if user A has 4 errors and user B has 4000, then logic strikes me that user B is doing something wrong.
But can I group the way I do? This is a modified version where the selection only grouped message and counted it, resolving so that ERROR FOO resulted in 4004 from my example over.
With your query, if the messages are different, then you will get multiple records per person.
If you only want one record per person, you would need to put an aggregate function around
messageFor example you could do:
Here I’ve changed
messagetoMIN(message)which will return the firstmessagefor this person, alphabetically.However if you are happy to return multiple records per person, then I see no problem with your script. It will show a list of
personidandmessageordered by the ones which are in the table the most, displaying only records which have amessagestarting withERR