logo

Back to questions

Unique Money Transfer Relationships

Easy

You are given a table of PayPal payments showing the payer, the recipient, and the amount paid. A two-way unique relationship is established when two people send money back and forth. Write a query to find the number of two-way unique relationships in this data.

Assumption:

  • A payer can send money to the same recipient multiple times.

Table:

Column NameType
payer_idinteger
recipient_idinteger
amountinteger

Example Input:

payer_idrecipient_idamount
10120130
20110110
10130120
30110180
20130170

Example Output:

unique_relationships
2

Explanation

There are 2 unique two-way relationships between:

  • ID 101 and ID 201
  • ID 101 and ID 301

PostgreSQL 14

Refer friends to get bonus content & cool prizes.