查找同一列中来自多个 MySQL 行的整数和?
让我们首先创建一个表 −
mysql> create table DemoTable739 (Price int); Query OK, 0 rows affected (0.65 sec)
使用插入命令在表中插入一些记录−
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)
广告