954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mysql sum fields

Hello,
I have a master/detail table, in the detail I have a filed payment and another field sum_payment, all I want is when a new record is inserting the values of the field payment to displayed in the field sum_payment. I tried default value but nothing supports this, also tried query's in Mysql Manager but I get a lock timeout

SELECT 
  SUM(user_payments.payment) AS Sum_payment
FROM
  user_payments

I want to every new record that is inserting the value of sum_payment to increase as the ammount of the payment, I want the total sum of the fields payment to held in the field sum_payment or I have to create a new table with relation to the detail and a field which will hold the sum?

Thank you
Kyriakos

kyriakos70
Newbie Poster
5 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

normally you wouldn't store the sum of all the payments together like this

normally you have a total and payments

total
TOTAL_ID
TOTAL_AMOUNT

payments
PAYMENT_ID
TOTAL_ID
PAYMENT_AMOUNT

you might need to add users into this, but you normally don't want a column to be updated from the sum constantly, calculate each time you do a select

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You