Answer the question
In order to leave comments, you need to log in
How to correctly form a window function into a query?
There is data:
cat_id | ad_id | count
60 | 1 | 22
60 | 99 | 22
60 | 3 | 22
42 | 5 | 14
42 | 4 | 14
11 | 12 | 6
11 | 19 | 6
11 | 2 | 6
cat_id | ad_id | count | row_num
60 | 1 | 22 | 1
60 | 99 | 22 | 1
60 | 3 | 14 | 1
42 | 5 | 14 | 2
42 | 4 | 14 | 2
11 | 12 | 14 | 3
11 | 19 | 6 | 3
11 | 2 | 6 | 3
SELECT *, ROW_NUMBER() OVER(
PARTITION BY cat_id
ORDER BY count desc
) AS row_num
FROM tabl
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question