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

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -