ETL: ROW_NUMBER() over (partition by field order by field desc) to find the 2 most visited URLs in each city

ETL: ROW_NUMBER() over (partition by field order by field desc) to find the two most visited URLs in each city

The source table is shown in the following figure: only two fields of city and url are provided. Now we need to find out the two most visited URLs in different cities. Therefore, we first need to count the number of visits to each url in each city, using group by( city,url). Then according to the city according to the number of url visits, sort from highest to bottom, use row_number() over (partition by field order by field desc), and finally select the first two to sort.
Insert picture description here

1. The temporary table counts the number of URL visits in each city

with temp as(select city,url,

Guess you like

Origin blog.csdn.net/zhengzaifeidelushang/article/details/111870768
Recommended