I have the following table for which I would like to obtain result based on the number of different TYPEs available for every CONTRACT_ID.
Table:
______________________________________________________________________________________
|Source | CONTRACT_ID | TYPE | ADDRESS | PHONE |
______________________________________________________________________________________
|Source1 | 1234 | INSURED | unique1 | 4321 |
______________________________________________________________________________________
|Source1 | 1234 | INSURED | unique1 | 4321 |
______________________________________________________________________________________
|Source1 | 1234 | DRIVER | unique1 | 4321 |
______________________________________________________________________________________
|Source1 | 1234 | INSURED | unique1 | 4321 |
______________________________________________________________________________________
|Source2 | 2345 | INSURED | unique2 | 5678 |
______________________________________________________________________________________
|Source2 | 2345 | DRIVER | unique2 | 5678 |
______________________________________________________________________________________
|Source2 | 2345 | CONTRACT | unique2 | 5678 |
______________________________________________________________________________________
Result:
______________________________________________________________________________________
|Source | CONTRACT_ID | ROLES | ADDRESS | PHONE |
______________________________________________________________________________________
|Source1 | 1234 | 2 | unique1 | 4321 |
______________________________________________________________________________________
|Source2 | 2345 | 3 | unique2 | 5678 |
______________________________________________________________________________________
i.e, The ROLES column in the result table should be the number of different TYPEs for a distinct CONTRACT_ID.
Can anyone help?