oracle sql assign unique number to each grouping 1

oracle sql assign unique number to each grouping

SELECT  t.*, DENSE_RANK() OVER (ORDER BY department desc, country desc) AS grp
FROM    mytable t

Here is what the above code is Doing:
1. The DENSE_RANK() function is used to assign a group number to each row. The OVER clause specifies the columns to use to determine the groups. In this case, the groups are determined by the department and country columns. The ORDER BY clause specifies the order in which the groups are assigned. In this case, the groups are assigned in descending order by department and then by country.
2. The SELECT clause specifies the columns to return. In this case, all columns are returned.
3. The FROM clause specifies the table to use.

Similar Posts