One measurement of link strength between two users (buddies) is the following:

S = (number of common buddies)/(number of buddies of person1 UNION number of buddies of person2)

To calculate the value above I have started to write the following query:

```
WITH user1 AS
(
SELECT calling_party, called_party FROM monthly_connections WHERE calling_party = 'a' OR called_party ='a'
),
user2 AS
(
SELECT calling_party, called_party FROM monthly_connections WHERE calling_party = 'b' OR called_party ='b'
),
commonUsers AS
(
SELECT COUNT (*) common_users_count FROM user1 u1 INNER JOIN user2 u2 ON u1.called_party = u2.called_party OR u1.calling_party = u2.calling_party OR u1.called_party = u2.calling_party OR u1.calling_party = u2.called_party
),
unionUsers AS
(
SELECT COUNT(*) FROM user1  UNION SELECT  COUNT(*) FROM user2
)

```

Then the number of unionUsers (which am not sure is written correctly) should be used as a denominator. Anyway I don't know how to complete the procedure in order to get the desired value so I would appreciate your help.

Thank you!