0
I have a table where are saved all services performed in several cars. The key is the car plate. A car can have more than one service performed per day. And for each service performed a new service id is created, even if it is for the same car.
I need to filter the 100 most frequent cars and I can’t because it’s inaccurate to save an id for each service.
Ex: car aaa1234 in the days 01,02,03 made 3 types of services per day. car bbb4321 on the days 01,02,03 made 1 type of service per day.
If I’m right, in my query, you’re accusing that the car aaa1234 is the most frequent. Since he did not want to count by quantity of service, but by frequency.
I’m not as skilled with querys and I can’t outrun that scope:
SELECT count(placa), placa
FROM [producao].[dbo].[servicos_teste]
group by placa
order by COUNT(placa) DESC
that’s right, but you already count the board once, you don’t need to repeat the command just give an alias to the COUNT and sort by it: SELECT Count(board) AS Qtd, board FROM [production]. [dbo]. [servicos_test] GROUP BY board ORDER BY Qtd DESC
– arllondias