从同一列的多个MySQL行中找到整数总和?
让我们首先创建一个表-
mysql> create table DemoTable739 (Price int);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable739 values(100); mysql> insert into DemoTable739 values(50); mysql> insert into DemoTable739 values(1200); mysql> insert into DemoTable739 values(500); mysql> insert into DemoTable739 values(800);
使用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)