I have the following query
SELECT em.id_employee, p.of_family, RANK () OVER (PARTITION BY p.des_family ORDER BY sum (sale) DESC) AS RankBySales,
sum (sale) as sale, sum (units) as units
FROM dim.employed as em, fact.venta as vt, dim.product as p
WHERE em.id_employed = vt.id_employee AND p.id_product = vt.id_product AND vt.id_calendario between 20180101 AND 20181231 GROUP BY em.id_employee, p.family
I need to rank the first 5 employees according to the sum of sales of each family of products but when doing the query, it shows me ranking from 1 to X in certain families and in others from 144 to Y, I do not understand what happens or how to get it alone the ids of employees of the first 5 places for each family.
I appreciate the help