// 查询所有性别为女的记录 mysql> select * from student where sex="女"; +----+------+-----+-----+------+ | id | name | sex | age | tell | +----+------+-----+-----+------+ | 2 | 李四 | 女 | 20 | - | +----+------+-----+-----+------+ 1 row in set (0.04 sec)
// age大于20的记录 mysql> select * from student where age>20; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 1 | 张三 | 男 | 23 | 13666665555 | | 5 | 王五 | 男 | 32 | 666666666 | +----+------+-----+-----+-------------+ 2 rows in set (0.00 sec)
// age小于等于20的记录 mysql> select * from student where age<=20; +----+-------+-----+-----+-------------+ | id | name | sex | age | tell | +----+-------+-----+-----+-------------+ | 2 | 李四 | 女 | 20 | - | | 3 | Tom | 男 | 13 | 13111115555 | | 4 | Jerry | 男 | 12 | 2333333 | +----+-------+-----+-----+-------------+ 3 rows in set (0.00 sec)
// age小于等于20并且id大于等于3的记录 mysql> select * from student where age<=20 and id >=3; +----+-------+-----+-----+-------------+ | id | name | sex | age | tell | +----+-------+-----+-----+-------------+ | 3 | Tom | 男 | 13 | 13111115555 | | 4 | Jerry | 男 | 12 | 2333333 | +----+-------+-----+-----+-------------+ 2 rows in set (0.03 sec)
// 按名字特征查询 mysql> select * from student where name like "%三%"; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 1 | 张三 | 男 | 23 | 13666665555 | +----+------+-----+-----+-------------+ 1 row in set (0.00 sec)
mysql> select * from student where name like "%o%"; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 3 | Tom | 男 | 13 | 13111115555 | +----+------+-----+-----+-------------+ 1 row in set (0.00 sec)
// tell 以5结尾的记录 mysql> select * from student where tell like "%5"; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 1 | 张三 | 男 | 23 | 13666665555 | | 3 | Tom | 男 | 13 | 13111115555 | +----+------+-----+-----+-------------+ 2 rows in set (0.00 sec)
mysql> select * from student where tell like "131%"; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 3 | Tom | 男 | 13 | 13111115555 | +----+------+-----+-----+-------------+ 1 row in set (0.00 sec)
mysql> select * from student where name="李四"; +----+------+-----+-----+-------------+ | id | name | sex | age | tell | +----+------+-----+-----+-------------+ | 2 | 李四 | 女 | 20 | 13900001111 | +----+------+-----+-----+-------------+ 1 row in set (0.00 sec)