求同一列中多个 MySQL 行的整数之和?
mysqlmysqli database更新于 2025/10/4 17:48:17
首先我们创建一个表 −
mysql> create table DemoTable739 (Price int); Query OK, 0 rows affected (0.65 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable739 values(100); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable739 values(50); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable739 values(1200); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable739 values(500); Query OK, 1 row affected (0.37 sec) mysql> insert into DemoTable739 values(800); Query OK, 1 row affected (0.20 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable739;
这将产生以下输出 -
+-------+ | Price | +-------+ | 100 | | 50 | | 1200 | | 500 | | 800 | +-------+ 5 rows in set (0.00 sec)
下面的查询是从同一列中的多个 MySQL 行中查找整数之和 −
mysql> select sum(Price) as Total_Price from DemoTable739;
这将产生以下输出 -
+-------------+ | Total_Price | +-------------+ | 2650 | +-------------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

