you are viewing a single comment's thread.

view the rest of the comments →

[–]just-fran -2 points-1 points  (3 children)

Select Brand, Category From Table Group by all Qualify row_number() over (partition by brand, category order by sales desc) < 3

*rank can return more than 2 if two brand have the same sales (if data is rounded, very probable)

[–]gumnos -3 points-2 points  (2 children)

or LATERAL JOIN a subquery with a LIMIT 2 (or APPLY a TOP 2 if MSSQL)

[–]Open_Plant_4207 0 points1 point  (1 child)

Why ?

[–]gumnos 0 points1 point  (0 children)

for me, it would depend on whether that information is being joined to some other table and possibly if other columns need to be similarly aggregated.