让我们首先创建一个表,其中一列为ID-
mysql> create table DemoTable ( ID int, StudentName varchar(10), CountryName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(0,'David','AUS'); mysql> insert into DemoTable values(3,'Chris','UK'); mysql> insert into DemoTable values(8,'Carol','US'); mysql> insert into DemoTable values(9,'Sam','US'); mysql> insert into DemoTable values(12,'Robert','UK'); mysql> insert into DemoTable values(10,'Mike','AUS');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+------+-------------+-------------+ | ID | StudentName | CountryName | +------+-------------+-------------+ | 0 | David | AUS | | 3 | Chris | UK | | 8 | Carol | US | | 9 | Sam | US | | 12 | Robert | UK | | 10 | Mike | AUS | +------+-------------+-------------+ 6 rows in set (0.00 sec)
以下是查找ID可被4整除的所有行的查询-
mysql> select *from DemoTable where (ID%4)=0;
输出结果
+------+-------------+-------------+ | ID | StudentName | CountryName | +------+-------------+-------------+ | 0 | David | AUS | | 8 | Carol | US | | 12 | Robert | UK | +------+-------------+-------------+ 3 rows in set (0.30 sec)