I have this code:
query = "SELECT SUM(amount) FROM set_payment777 GROUP BY customer_VAT"
mycursor.execute(query)
for row0 in mycursor:
query = "SELECT SUM(amount) FROM customers_payments777 GROUP BY customer_VAT"
mycursor.execute(query)
for row1 in mycursor:
final_row = row0[0] - row1[0]
I have 2 tables in MySQL. They both store different amounts. I want to get the amounts from the table named "set_payment777" and subtract all its stored amount from the amounts stored in the table named customers_payments777.
For instance, we store the amount 150 in the table set_payment777 and the amount 25 in the other table. These 2 amounts are linked with the customer's VAT number. I can subtract the first set of numbers(150-25). The problem is when I have more than 1 customer. Let's say that the first customer has the VAT number 000000000 and the second customer the VAT number 111111111. If the first has the amounts 150 and 25 I can print 125 because 150-25 = 125. Now if the second customer has the amounts 200 and 50 it doesn't subtract 50 from 200 it subtracts 50 from 150 (the first customer's amount).
It is a little complicated but can someone find a solution?