1

Scenario:

I have a MySql Database called "tblreqslipdetails" it has a field "subtotals" which has a value = Integer (ex. 4500.50, 2500, 3500.57.. so on..) it also has a field which has "idcategory" which has a value of (2, or 4 or 5).

Question:

How can I create a query base on my "idcategory" and add the value in my field "subtotals"?

Like:

From Where ID="idcategory" add array??? "not sure really" "subtotal" = Total

To cut it short, I would like to create a simple script where I can add the subtotals from my fields..

Thanks in advance.

2
  • Your requirement is not clear but I think you are looking for UPDATE query. Commented Oct 25, 2013 at 8:15
  • even a Simple Query will be okay Sir. I just want to know how to add the values from my subtotal field Where my ID="myPreferredID".. I will just add the Total Value Later in the form.. Sorry not really good in SQL arrays. Commented Oct 25, 2013 at 8:19

1 Answer 1

1

Like what Vijay said i think you are looking for an UPDATE.

UPDATE `tblreqslipdetails` SET `subtotals`=`subtotals`+2000 WHERE `idcategory`=2
Sign up to request clarification or add additional context in comments.

5 Comments

UPDATE tblreqslipdetails SET subtotals=subtotals+2000 WHERE idcategory=2 = (so this is the code that I need Sir?) (+2000 means) - really sorry about this. Not really good in adding multiple values of a certain field. But really Thank you!
You don't have to use +2000 it was just an example. replace that with the amount you would like to add. Suppose the record that has the idcategory=2 has a subtotals of 4500. The query above would make the subtotals=6500
Oh okay Sir. Thanks for being patient. That is my problem really. How would I be able to add the values in my field "subtotal" automatically. My field can have so much values so I cannot determine the exact values to be Added. Ex: In my ID="2" category, I have 25 subtotal amounts to be added. In my ID="3" I have 10 values to be added. So I will be needing some like a counter to count how many values added in the field "subtotal" then add it all up. Thank you! Thank you! Thank you!
ID='2' has 25 subtotal ID='3' has 10 values? Then what you'll need is two tables in a parent / child relationship. This way the child table can contain an infinite number of record all referencing the parent table.
Yup, followed your instructions just now. I have a Parent and Child relationship in my DB. I am now able to Query the subtotal field from my child table base on my parent table. So my problem now is... How to be able to query ADD those subtotals for me to be able to get their True Total.. Thanks so much..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.