Home > Backend Development > PHP Tutorial > php mysql sum statement_PHP tutorial

php mysql sum statement_PHP tutorial

WBOY
Release: 2016-07-13 17:04:31
Original
2136 people have browsed it

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630860.htmlTechArticlephp tutorial mysql tutorial sum statement // Automatically calculate the value 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 = se...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template