DataBases
简介
MariaDB
MySQL
数据类型
创建表
索引 index
主键 primary key
外键 foreign key
数据导入与导出
where条件判断
用户授权与密码
数据备份与恢复
数据热备
主从同步
读写分离
多实例
分库分表
集群-MHA
集群-PXC
存储引擎
本文档使用 MrDoc 发布
-
+
首页
where条件判断
字符匹配,条件为字段A大于字段B ```asp select username,uid,gid from db3.user where uid > gid; ``` 字符匹配,条件为字段A等于字段B ```asp select username,uid,gid from db3.user where uid = gid; ``` 字符匹配,条件为字段A不等于(!取反)字段B ```asp select username,uid,gid from db3.user where uid != gid; ``` 范围内匹配,in包含内容匹配 ```asp select username from db3.user where username in ("mysql","nginx"); ``` 范围内匹配,not in不包含内容匹配 ```asp select username from db3.user where username not in ("mysql","nginx"); ``` 范围内匹配,某个区间的内容匹配 ```asp select id,username from db3.user where id between 10 and 20; ``` 范围内匹配,去掉重复值 ```asp select distinct shell from db3.user; ``` 匹配空null ```asp select username from db3.user where comment is null; ``` 匹配非空not null ```asp select username from db3.user where comment is not null; ``` 逻辑匹配,1个条件成立匹配 ```asp select username,uid from db3.user where username="root" or uid=1; ``` 逻辑匹配,2个条件同时成立匹配 ```asp select username,uid from db3.user where username="root" and uid=0; ``` 模糊匹配,like匹配_代表1个字符,满足1个字符匹配 ```asp select username from db3.user where username like '_'; ``` 模糊匹配,%%内包含字符即匹配 ```asp select username from db3.user where username like '%a%'; ``` 模糊匹配,以a开头的即匹配 ```asp select username from db3.user where username like 'a%'; ``` 模糊匹配,至少4个字符即匹配 ```asp select username from db3.user where username like '__%__'; ``` 正则匹配,元字符^开头的匹配 ```asp select username from db3.user where username regexp '^a|^d'; ``` 正则匹配,元字符^开头[]和|一个效果 ```asp select username from db3.user where username regexp '^[ad]'; ``` 正则匹配,包含范围内数字即匹配 ```asp select username from db3.user where username regexp '[0-9]'; ``` 匹配结果并排序,asc对匹配出来的结果做升序(asc默认可以不加) ```asp select username,uid from user where uid <=1000 order by uid asc; ``` 匹配结果并排序,desc对匹配出来的结果做降序 ```asp select username,uid from user where uid <=1000 order by uid desc; ``` 匹配结果并分组,group by对匹配出来的结果做分组 ```asp select shell from user where uid <=100 group by shell; ``` 匹配结果并再匹配一次,having对匹配出来的结果在按照条件匹配一次 ```asp select * from user where username is not null having uid <=30; ``` 限制查询结果显示行数,linit+数字多少就显示开头的多少行 ```asp select * from user limit 2; ``` 限制查询结果显示行数,linit+行数+步长(第2行开始输出5行) ```asp select * from user limit 2,5; ```
done
2024年5月11日 09:21
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码