让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Name varchar(20), -> Amount int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John',200); mysql> insert into DemoTable values('Chris',150); mysql> insert into DemoTable values('Mike',500); mysql> insert into DemoTable values('John',350);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+-------+--------+ | Name | Amount | +-------+--------+ | John | 200 | | Chris | 150 | | Mike | 500 | | John | 350 | +-------+--------+ 4 rows in set (0.00 sec)
这是忽略特定记录并添加剩余记录(数字)的查询-
mysql> select sum(Amount) from DemoTable -> where Name!='John';
这将产生以下输出-
+-------------+ | sum(Amount) | +-------------+ | 650 | +-------------+ 1 row in set (0.00 sec)