查询

1. 重命名表: 

eg:select s.name as 姓名, s.age as 年龄 from students as s;

2. 去重查询:

select distinct 字段 from 数据表名;

3. 条件查询:

select from 数据表名 where (not) ... and(or) ... ;

4. 模糊查询

like: select 字段 from 数据表 where 字段 like “...” 用%代替未知的部分 ,_ 表示位数。

eg:查询姓名中以“小”开始的名字:select name from students where name like “小%”;

查询姓名中有“小”的名字:select name from students where name like “%小%”;

查询姓名为2个字的名字: select name from students where name like “__”;

查询姓名至少2个字的名字: select name from students where name like “__%”;

 

rlike 正则: select 字段 from 数据表 where 字段 rlike “...” ^ 表示以什么开头,$表示以什么结尾 ,.*代替未知部分。

eg: select name from students where name rlike “^周.*伦$”; 查询名字以周为开头,伦为结尾,中间可能有字的名字。

 

5. 范围查询:

  • 查询非连续范围

select *  from 数据表名 where 字段 in(...,...);

eg: select name,age from students where age in(12,24,34);

eg:select name,age from students where age not in(12,24,34);

  • 查询连续的范围

select *  from 数据表名 where 字段 between ... and ...;

eg: select name,age from students where age between 12 and 24;  查询年龄在12至24的信息

eg: select name,age from students where age not between 12 and 24; 查询年龄不在12至24的信息

  • 空判断

select * from 数据表名称 where 字段 is null;

select * from 数据表名称 where 字段 is not null;

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值