Phpmysql summation statement _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Phpmysql summation statement. Php Tutorial mysql tutorial summation statement automatically calculates the value of two fields and assigns it to another field SQL $ sqlupdatetablesetsummathe + language; calculates the total data of one field column $ sqlse php Tutorial mysql tutorial summation statement

// Automatically calculate the values of the two fields and assign them to another SQL field

$ SQL = "update table set sum = mathe + language ";

// Calculate the total data of a field column

$ SQL = "select sum (sum) from tables ";

// Let's look at an instance.

/*
Create a 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 the two fields and assign them to another SQL field
Update sumtable set summ = a1 + a2

// Sum
SELECT sum (summ) FROM sumtable
Sum (summ)
21

// Source www. bKjia. c0m

In the mysql tutorial, the sum statement // automatically calculates the values of the two fields and assigns them to another field. SQL $ SQL = update table set sum = mathe + language; // calculate the total data of a field column $ SQL = se...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.