I have the following table with multiple entries:
Country | Date | Manufacturer |
---|---|---|
UK | 01-01-2020 | VW |
UK | 01-01-2020 | VW |
UK | 01-02-2020 | VW |
Denmark | 13-01-2020 | Audi |
........ | ....... | ....... |
Each line represents the sale of a car, from a country, from a specific date and the manufacturer of the car sold. I have data from two months (January and February of 2020), for two countries, UK and Denmark. In these months multiple car manufacturers have sold cars (not only VW and Audi as the table shows). I want to obtain for each country and each month the most sold cars for a certain manufacturer and the number of cars sold for that specific manufacturer.
I tried this code:
SELECT
Country,
DATENAME(MONTH, Date) AS Month,
Manufacturer,
COUNT(*) AS no_of_sales
FROM
table
GROUP BY
Country,
DATENAME(MONTH, Date),
Manufacturer
ORDER BY
no_of_sales DESC
But this way I obtain for each country, each month and for each manufacturer how many cars they sold. I want to obtain only 4 rows in this case:
Country | Date | Manufacturer | no_of_sales |
---|---|---|---|
UK | January | VW | 13 |
UK | February | Porsche | 15 |
Denmark | January | VW | 10 |
Denmark | Februray | Audi | 12 |
Basically I am not sure how to filter the select statement that I wrote above. Hope I was clear enough for you to understand.