Heim  >  Artikel  >  Backend-Entwicklung  >  php mysql 求和语句_PHP教程

php mysql 求和语句_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:04:312051Durchsuche

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

//本站原创文章转载注明来源www.bKjia.c0m

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630860.htmlTechArticlephp教程 mysql教程 求和语句 //自动计算二个字段的值赋给另一字段sql $sql =update table set sum = mathe +language; //求一个字段列的数据总和 $sql = se...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn