I have a table like this in Snowflake. It supports ANSI SQL, so don't worry if this DB isn't familiar to you.
| Salesman | Customer | Country |
|---|---|---|
| Brown | Super Company | UK |
| Brown | Another customer | UK |
| Smith | Contoso | US |
| Brown | Test company | US |
I'd need to find where each salesman have most of customers. So desired response for the query would be like this.
| Salesman | Country | cnt(country) |
|---|---|---|
| Brown | UK | 2 |
| Smith | US | 1 |
I've come up with this
SELECT
salesman,
country,
max(count(country))
FROM
customertable
GROUP BY
salesman, country
But nested aggeregation functions aren't supported. And I've already read quite good reasons for that. But I just cannot find a way to do that in any other way.