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