In a DB2 database I have 2 tables

```
  attribute
  ---------
  attribute_id      name
  1002                  xyz
  1012                  abc
  1023                  lmn
  1057                  def
  1076                  qwe

  storecatattrrel
  ---------------
  store_id      category_id      attribute_id
  100                  10007            1012
  100                  10007            1057
  100                  10007            1023
  101                  10005            1002
  101                  10006            1002
  101                  10007            1057
  101                  10007            1002
  101                  10007            1023
  101                  10007            1076

```

I am trying to create an SQL query using which I want to assign sequence value to attributes in category-store-attribute relationship based on alphabetical order of attribute name like below.

```
  store_id      category_id      attribute_id      sequence
  100                  10007            1012              1
  100                  10007            1057              2
  100                  10007            1023              3
  101                  10005            1002              1
  101                  10006            1002              1
  101                  10007            1057              1
  101                  10007            1002              4
  101                  10007            1023              2
  101                  10007            1076              3

```

I tried using ROW\_NUMBER function but without any luck.

```
select b.store_id, b.category_id, b.attribute, a.name, ROW_NUMBER() OVER(partition by attribute_id) from storecatattrrel b
    inner join attribute a on a.attribute_id = b.attribute_id
    order by name asc;

```

I could not find a way to group the results based on store\_id, category\_id and attribute\_id and then assign the sequence.

Any help would be appreciated!