cte
that selects paid_by
as user_id
and -amount
as amount
from Transactions
to represent money going out.paid_to
as user_id
and amount
as is to represent money coming in.user_id
to get the net transaction amount for each user.Users
table with the CTE to combine user information with their transaction summary.CASE
statement to determine if the credit limit is breached by checking if the current credit is less than 0.user_id
, user_name
, credit
, and credit_limit_breached
.erDiagram Users { int user_id PK varchar user_name int credit } Transactions { int trans_id PK int paid_by FK int paid_to FK int amount date transacted_on }