Have a query that shows this…
salesPersonId Total
------------- -----------
AB4 3
GT10 2
JB9 1
JS1 2
KT8 4
TC3 4
VG7 2
WC2 7
(8 row(s) affected)
My query is…
SELECT so.salesPersonId, COUNT(so.orderId) AS 'Total'
FROM salesOrder AS so
GROUP BY so.salesPersonId
GO
I wanted to do this…
SELECT so.salesPersonId, COUNT(so.orderId) AS 'Total'
FROM salesOrder AS so
WHERE MAX(COUNT(so.orderId))
GROUP BY so.salesPersonId
GO
This gives me an error, any ideas on how to show only the salesPersonId with the highest total? Here being WC2.
You can use a common table expression (or a subquery) to get the breakdown and then select all entries in your CTE where their total is equal to max total (as there may be more than one):