search
Homephp教程php手册php mysql 求和语句

自动计算二个字段的值赋给另一字段sql:

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

求一个字段列的数据总和:

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

下们我们来看个实例,创建表代码如下:

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 INTO `cc`.`sumtable` ( 
`id` , 
`a1` , 
`a2` , 
`summ`  
) 
VALUES ( 
'1', '5', '5', '0' 
), ( 
'2', '6', '5', '0' 
); 
*/
 
//自动计算二个字段的值赋给另一字段sql 
update sumtable set summ = a1+a2 
//求和 
SELECT sum( summ ) FROM sumtable  
sum(summ)   
21

                     


文章地址:

转载随意^^请带上本文地址!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool