mar
mar

Reputation: 53

Summing values and inserting to database

I have this sql command that sums up the value from a,b,c and d. and i want it to be stored in my table in the column total. Is this the correct query? How to store the total value?

$sql = "SELECT sum(a + b + c + d) as total_value FROM tablename WHERE form_no = '$formnumber'";

Upvotes: 0

Views: 42

Answers (2)

Haseena P A
Haseena P A

Reputation: 17406

$sql = "SELECT (a + b + c + d) as total_value FROM tablename WHERE form_no = '$formnumber'";

where a,b,c,d are column name..

This is working fine..check it

Upvotes: 0

Barmar
Barmar

Reputation: 781848

UPDATE tablename
SET total_value = a + b + c + d
WHERE form_no = '$formnumber'

Upvotes: 3

Related Questions