Ive been looking at several articles on stack but not been exactly specific to what I need
I have a table with application names, teams, service, directorate and username
I want to bring back the application name, team, service, directorate back of the highest used location (team, service, directorate) based on user, ie usercount
SELECT [ApplicationName]
,[Team]
,[Service]
,[Directorate]
,count(distinct username) Usercount
FROM
[Windows7data].[dbo].[devices_users_apps_detail] a
GROUP BY
[ApplicationName]
,[Team]
,[Service]
,[Directorate]
ORDER BY
[ApplicationName],
count(distinct username) desc;
I have played with by adding to the above nested subqueries, having statements etc but this has not worked