I am trying to write a select statement using Postgres to get the top 3 users in each problem category with the most problem incidents.
For example:
email problems:
mary 5
jason 3
amy 2
beth 1
riley 1
network problems:
bob 7
john 6
fred 4
howard 2
amy 1
sue 1
The results would produce:
email problems:
mary 5
jason 3
amy 2
network problems:
bob 7
john 6
fred 4
This contains the subselect that works so far to get me the count of problems by category sorted by count descending within each category. Now I need to extract out the top 3 from each category.
SELECT subtable.type,subtable.requestor,subtable.foo
FROM
(SELECT type as type,requestor as requestor,count(*) as foo
FROM incident
group by type,requestor
ORDER BY type,count(*) DESC) subtable
??????????????????????;
Any help would be much appreciated! Laura
For example:
email problems:
mary 5
jason 3
amy 2
beth 1
riley 1
network problems:
bob 7
john 6
fred 4
howard 2
amy 1
sue 1
The results would produce:
email problems:
mary 5
jason 3
amy 2
network problems:
bob 7
john 6
fred 4
This contains the subselect that works so far to get me the count of problems by category sorted by count descending within each category. Now I need to extract out the top 3 from each category.
SELECT subtable.type,subtable.requestor,subtable.foo
FROM
(SELECT type as type,requestor as requestor,count(*) as foo
FROM incident
group by type,requestor
ORDER BY type,count(*) DESC) subtable
??????????????????????;
Any help would be much appreciated! Laura