MariaDB [zachary]> select * from test; 查询表中所有数据 +----+---------+------+---------------------+ | id | name | sex | email | +----+---------+------+---------------------+ | 1 | zachary | m | zachary_yzh@126.com | | 2 | marry | f | marry@163.com | | 3 | jack | m | jack@qq.com | | 4 | mali | NULL | mali@foxmail.com | +----+---------+------+---------------------+ MariaDB [zachary]> update test set sex='f' where id=4; 修改mali的性别 MariaDB [zachary]> select name from test where sex='m';查看表中的男性都有谁。 MariaDB [zachary]> select name from test where id >=3; id大于3的人 MariaDB [zachary]> select name from test where id >=2 and id <=4;使用逻辑运算确定查询条件。表示id在2到4之间的人。逻辑运算符有and or not MariaDB [zachary]> select name from test where id between 2 and 4;使用between and关键字来确定区间范围。between and为闭区间 MariaDB [zachary]> insert into test (id,name)value(5,'tom');插入tom的信息。 MariaDB [zachary]> select * from test where name='tom'; 查看tom的信息。插入时没有插入性别。使用在创建表时所使用的默认值。 +----+------+------+-------+ | id | name | sex | email | +----+------+------+-------+ | 5 | tom | m | NULL | +----+------+------+-------+ 1 row in set (0.01 sec) MariaDB [zachary]> select name from test where email rlike '.*[(163)|(126)].*'; 查看使用网易邮箱的人有哪些,rlike为正则表达式匹配方式 MariaDB [zachary]> select * from test where name like '__r%';通配符匹配查询方式使用like关键字,查询名字中第三个字母为r的用户信息。_表示任意单个字符,%表示任意长度的任意字符。 MariaDB [zachary]> select * from test where email is null;查询没有使用邮箱的用户。在查询关键字为NULL时不能使用==号来进行匹配,要使用is null 或者is not null。 |