Skip to content
Advertisement

If a table has columns equal to columns in a second table insert values in a third table, python – mysql

I have 3 table in my database:

  • Borrowers: amount of the loan, interest rate, borrower id (PK)
  • Lenders: amount of the bid, interest rate and LenderID (PK)
  • Contracts: ContractID PK, amount, interest rate and the two foreign key(borrowerID, lenderID)

I create a loop in python with an input command in which I can insert new request of loan and new bid offer. Every insertion is connected with mysql and it is added to the respective table.

For example:

input in python –> L 1000 1.1 output –> create an insertion in Borrowers table with an auto_incremental PK, an amount of 1000 and an interest rate of 1.1%

I need to create another function in the loop in which, for every new request/offer, if an offer is equal to a request (Borrowers.Amount, BorrowersInterestRate = Lenders.Amount, Lenders.InterestRate), it will be created an insertion in contracts table with the same amount and interest rate.

Advertisement

Answer

This is only works if you are using mysql python connector. As far as I know that is the only way to use mysql using python but I maybe wrong.

to search if request matches the offer:

JavaScript

to search if offer matches request:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement