游戏脚本LUA训练营:MySQL学习日记(五)——单表查询

MySQL数据库–单表查询

  • 区间查询:

     between...and...
    

执行select * from student1 where age between 20 and 22;
在这里插入图片描述

  • 模糊查询

     like...
    

%表示任意字符 _表示单个字符。
查找名字第一个字为铁的学生的全部信息:select *from student1 where name like ‘铁%’;
查找名字第二个字为刚的学生的全部信息:select *from student1 where name like ‘_刚’;
在这里插入图片描述

  • 正则表达式查询

      rlike..
    

查询所有以a或b开头的学生的所有信息 select * from student1 where name rlike ‘1.*$’;
在这里插入图片描述

  • 过滤重复项

     distinct
    

查询学生的所有年龄select distinct age from student1;

在这里插入图片描述

  • 有限列表

     in...
     not in...
    

查询年龄是21或22岁的学生的信息:select * from student1 where age in (21,22);
查询年龄不是21或22岁的学生的信息:select * from student1 where age not in (21,22);
在这里插入图片描述

  • 排序

     order by   asc /desc 
    

按年龄升序查询所有学生的信息:select * from student1 order by age asc;
在这里插入图片描述
按年龄降序查询所有学生的信息:select * from student1 order by age desc;
在这里插入图片描述

  • 分组

     group by
    

select age,name,sex from student1 group by sex;
显示
在这里插入图片描述

限定查询结果条数

	select 列名 from 表名 [where..] [ limit n] [offset m];
	lmit n:返回n条记录 offset m:跳过m条记录
	offset 不可单独使用不

在这里插入图片描述

select 列名 from 表名 【where..】  limit m,n;
limit m,n 相当于 limit n offset m

在这里插入图片描述

  • 结果别名显示

     as
    

select name as stu_name from student1;
在这里插入图片描述

  • 过滤

select count(age) as num,age from student1 group by age having num>1;**
在这里插入图片描述


  1. ab ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值