sql - create serial numbers based on multiple columns -
i have following data
i want create index level shown in last column based on region, country, store type , location column. region column have own serial number each new region i.e. 'apac 1 , emea 2' same other columns(country, store type, location). have tried use partition result not able desired results.
use dense_rank() window function.
select *, concat( dense_rank() over(order region), ',', dense_rank() over(partition region order country), ',', dense_rank() over(partition region, country order [store type]), ',', dense_rank() over(partition region, country, [store type] order location) ) [index level] tab
Comments
Post a Comment