mysql学习笔记(5)
来源:互联网 发布:网络提现 需要牌照 编辑:程序博客网 时间:2024/05/18 22:44
查询——select
1.查询【user】表中数据
select * from user; # 查询【user】表中所有数据
select id,name from user; #查询【user】表中id列和name列的数据
2.给字段取个别名 as/空格
select id,name( as) n,pass( as) p from user;
3.distinct关键字的使用(取出唯一值)
select distinct age from user # 把age列的值取出并去重)
4.使用where条件进行查询
select * from user where id=3;
5.查询空值null和非空值
select * from user where pass is null;
select * from user where pass is not null;
6.between and 的用法
select * from user where id between 3 and 5;
7.in 的用法
select * from user where id in(1,3,5);
8.like 的使用方法(模糊查询)
# %匹配所有字符,_匹配一个字符
select * from user where name like '%4%';
select * from user where name like '%4%' or name like '%5%';
# 用正则表达式(regular express)# 但是会慢
select * from user where name regexp '4';
select * from user where name '(.*4.*)|(.*5.*)';
# 正则复习
'4' # 包含4的
'4$' # 以4结尾的
’^u' # 以u开头的
'.*s.*' # 包含s的
9.使用order by 对结果进行排序
select * from user order by name;
# 默认升序排列,升序"... order by ... asc;",降序"...order by ... desc;"
# 按字段排序,如果是string并不是按自然数排序,string需要按数字大小排序方法如下
select * from user order by -name asc; # 降序
select * from user order by -name desc; # 升序
select * from user order by (name+1); # 升序
10.使用limit限定输出个数
select * from user order by name limit 1,3;
limit 1,3 # 从1号位(第二位)开始取3个
limit 5 #从开头取5个
- mysql学习笔记(5)
- MYSQL学习笔记(5)
- MySQL学习笔记5(视图)
- MySQL 学习笔记(5)MySQL常用函数汇总
- mysql学习笔记(一)
- MYSQL学习笔记(1)
- mysql学习笔记(未完)
- MySQL学习笔记(1)
- MySQL学习笔记(一)
- MySQL学习笔记(二)
- MySQL学习笔记(三)
- MySQL学习笔记(四)
- MySQL学习笔记(五)
- MySQL学习笔记(六)
- MySQL学习笔记(七)
- MySQL学习笔记(八)
- MySQL学习笔记(九)
- mysql学习笔记(1)
- 学习资源
- QThread中的互斥、读写锁、信号量、条件变量
- 深入分析nutch的抓取流程
- 两个list集合得到linq外连接的效果
- Service的生命周期
- mysql学习笔记(5)
- 利用selenium webdriver下载不同类型的文件(pdf,txt等等)
- C# 迭代器简析
- Java根据用户IP查找用户地址信息
- 关于"LNK2005"错误
- 无效的字段名或字段索引
- 九度oj-1471-合并字符
- 手机安全卫士简单实现原理
- 平方根升余弦滤波器