I've got a Oracle 11g table as follows:
id name department
1 John Accounting
2 Frederick BackOffice
3 Erick Accounting
4 Marc BackOffice
5 William BackOffice
6 Pincton Accounting
7 Frank Treasury
8 Vincent BackOffice
9 Jody Security
I want to query the table getting all records, and for each record assigning a sequence to the department, so the result would be something like this:
1 John Accounting 1
2 Frederick BackOffice 2
3 Erick Accounting 1
4 Marc BackOffice 2
5 William BackOffice 2
6 Pincton Accounting 1
7 Frank Treasury 4
8 Vincent BackOffice 2
9 Jody Security 3
I know I can get the sequence number for each record inside their department, using rownum over partition by..., the question is how I can do the 'same' at a group level, assigning a sequence to each group(let's say the order is by department name, as in the example). Any ideas?