php tutorial mysql tutorial sum statement
//Automatically calculate the values of two fields and assign them to another field sql
$sql ="update table set sum = mathe +language";
//Find the sum of data in a field column
$sql = "select sum(sum) from tables";
//Let’s take a look at an example
/*
Create table
CREATE TABLE `cc`.`sumtable` (
`id` INT( 4 ) NOT NULL ,
`a1` INT( 4 ) NOT NULL ,
`a2` INT( 4 ) NOT NULL ,
`summ` INT( 8 ) NOT NULL
) ENGINE = InnoDB
Insert record
INSERT INTO `cc`.`sumtable` (
`id` ,
`a1` ,
`a2` ,
`summ`
)
VALUES (
'1', '5', '5', '0'
), (
'2', '6', '5', '0'
);
*/
//Automatically calculate the values of two fields and assign them to another field sql
update sumtable set summ = a1+a2
//Sum
SELECT sum( summ ) FROM sumtable
sum(summ)
21
//Reprinted original articles on this site indicate the source www.bKjia.c0m