1

I need to check the sequence number generated of the client per risk , per policy ( E.g. starts at 1 for each risk and is incremented by 1 for each client) in table1. Assign sequence number 1 if the Client is having the Role_ID as ‘A’ in Table2 and assign 2 if the Client is having Role_id as ‘B’ .
After that table 1 will look like

policy       risk          Risk_Sequence_No          Client_Id          Tab2.role_id
---------------------------------------------------------------------------------------
989898989      1                  1                  1000000001        A
989898989      1                  2                  1000000002        B
989898989      2                  1                  1000000001        A
989898989        2                2                  1000000002        B
989898989      3                  1                  1000000001        A
170023233      1                  1                  1000000004        A
170023233      1                  2                  1000000005        B

Table 2 :

policy Client_Id role_id

989898989     1000000001                 A
989898989     1000000002                 B
170023233     1000000004                 A
170023233       1000000005                 B
1
  • 1
    There is no role_id in your example. Commented Sep 18, 2014 at 13:13

1 Answer 1

1

There is no role_id in your example, but the general solution to this kind of problems are window functions:

select policy,
       risk,
       row_number() over (partition by policy order by client_id) as risk_sequence_no
       client_id
from the_table
order by policy, risk, client_id;
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for the solution. But this is not giving me correct results. as in table Risk_Sequence_No can only be 1 or 2 with condition as sequence number 1 if the Client is having the Role_ID as ‘A’ in Table2 and assign 2 if the Client is having Role_id as ‘B’ . The Role_ID will be taking by joining table 1 and table 2.
@Avi: please add the role_id to your example
Hi, Thanks for help. Added table 2 for refrence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.