Example Table & DataName JobTitle GroupID SubGroupIDHan Solo Pilot 1 APricess Leia Politician 1 AChewbacca Pilot 1 ARiggs Pilot 1 ALuke Skywalker Jedi Knight 1 BYoda Jedi Knight 1 BDarth Vader Sith Lord 1 BBoba Fett Bounty Hunter 2 ABossk Bounty Hunter 2 A
I need to group on a field alias ((GroupID+SubGroupID) AS JobCat), count the number of times a JobTitle appears in each JobCat group, then return the JobTitle and JobCat for only the JobTitle that has the max count for that group.Example Query Return JobTitle JobCatPilot 1AJedi Knight 1BBounty Hunter 2A
I have figured out how to return the count of the max occurring JobTitle and the JobCat, but not the associated JobTitle.select MAX(TitleCount) AS TitleCount, (GroupID+SubGroupID) AS JobCatfrom ( SELECT JobTitle, COUNT(JobTitle) AS TitleCount FROM ExampleTable GROUP BY JobTitle) as x inner join ExampleTable as f on f.JobTitle = x.JobTitle GROUP BY (GroupID+SubGroupID) ORDER BY (GroupID+SubGroupID);
Any help would be greatly appreciated.Thanks,Reed