SOLVE

LATER

Canteen Logs

Problem

Editorial

Analytics

Fredo and his friends regularly visit their college canteen. As with any group, on a day , one of the friends pays the canteen bill of all the friends. You are given a table of logs which shows the entries of transactions between friends. The table consists of three fields as described below:

1. **P1**: Name of the person who pays the bill.

2. **P2**: Name of the person whose bill is paid by **P1**.

3. **amount**: Amount paid by **P1** for **P2**.

You have to summarise the transaction between all pairs of friends. See the sample input and output for explanation.

Table : **logs**

Field | Type |
---|---|

P1 | text |

P2 | text |

amount | int |

Field | Type |
---|---|

P1 | text |

P2 | text |

NetAmount | int |

**Sample logs Table:**

P1 | P2 | amount |
---|---|---|

Fredo | Zeus | 81 |

Fredo | John | 59 |

Zeus | Fredo | 81 |

Zeus | John | 16 |

John | Fredo | 27 |

John | Zeus | 83 |

Fredo | Zeus | 27 |

Fredo | John | 17 |

P1 | P2 | NetAmount |
---|---|---|

Fredo | John | 49 |

Fredo | Zeus | 27 |

John | Zeus | 67 |

**Explanation**:

Here Fredo lends John 59+17=76 and John lends Fredo 27. So, in all John owes Fredo 49 units.

Similarly, Fredo lends Zeus 81+27=108 and Zeus lends Fredo 81. So, in all Zeus owes Fredo 17 units.

Similarly, Zeus owes John 67 units.

**Note**:

Only direct transactions are to be covered in the output table.

Only those entries should come in the output table which have **NetAmount greater than 0**.

The output table should be ordered by **P1** in ascending order and then by **P2** in ascending order.

It is guaranteed that the input table will contain all ordered pairs of friends atleast once.

Time Limit:
5 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
MySQL,
PostgreSQL,
MSSQL,
Oracle Database

Initializing Code Editor...

{"6f46e6f": "/pagelets/problem-author-tester/sql/canteen-logs/", "6f46e99": "/pagelets/recommended-problems/sql/canteen-logs/", "6f46e85": "/pagelets/problems-hint/sql/canteen-logs/", "6f46e33": "/pagelets/show-submission/sql/canteen-logs/", "6f46e58": "/pagelets/suggested-problems/sql/canteen-logs/"}

{}

realtime.hackerearth.com

80

426bba2de1163d0fa5ea31360c4f51f9644a1d3e

58a29e5cae2309f04b28

/realtime/pusher/auth/