sql - create serial numbers based on multiple columns -


i have following data

enter image description here

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

Popular posts from this blog

php - Autoloader issue not returning Class -

ruby - Prevent Custom Validation Error on Association -

c++ - Why am i getting wrong values when performing PE base relocation? -