0

I have a total of three tables with a many-to-many relationship.

1.) users

id | email
-----------
1  | usera@example.com
2  | userb@example.com
3  | userc@example.com

2.) accounts

id | userId | availableBalance | currencyCode
1  | 1      | 30               | USD
2  | 2      | 12               | USD
3  | 3      | 0                | USD

3.) transactions

id | accountId | toId | amount | currencyCode | pending
1  | 2         | 1    | 6      | USD          | true
2  | 2         | 3    | 6      | USD          | true
3  | 2         | 1    | 6      | USD          | true

B has one account and its balance value is 12 USD, and he creates three transactions 1,2 and 3 for user A, C, and A.

  1. I want to check how many transactions can be successfully made.
  2. if user b has only 6 USD and he created two transaction one for a user a and one for user b with same amount 6 USD. Then as a user A I want to count this type of transaction that he can get money or he may not.
  • Total sum of transactions is above the balance. So the transactions priority (as a variant - their order) must exist. – Akina Sep 15 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.