mysql之DQL(1)

简介

DQL:DataBase Query language 用来查询数据,不会对数据造成变化。把查询的结果发送到客户端进行显示。查询的结果为一个虚拟表。

1,基础查询

1,查询所有列:

select * from 表名;
2,查询指定列:
select 列名1,列名2,.. from 表名;

2,条件查询


条件查询在查询的时候将条件放在where后面,where后条件的关键字有:

=(等于)

<(小于)

 >(大于)

 !=(不等于)

<>(不等于)

<=(小于等于)

>=(大于等于)

and (表示所有条件都必须满足) 

or(表示所有条件中有一个满足就可以)

is null(为空)  is not null(不为空) 

between ........ and.....(表示从指定开始的值到结束的值,包含开始值和结束值)

in(set) 查找多个符合条件的内容。使用集合表示,多个值之间用逗号

not(set)查找多个不符合条件的内容。

示例:

-- 创建student表
create table student(
sid int primary key,
age int,
name varchar(255),
gender varchar(255)
)
-- 1.查询年龄为15的学生
select * from student where age=15;
-- 2.查询年龄不为15的学生 
select * from student where age<>15;
-- 3.查询年龄在25以上的学生
select * from student where age>15;
-- 4.查询年龄为15且性别为男的学生
select * from student where age=15 and gender="男";
-- 5.查询年龄为15或性别为女的学生
select * from student where age=15 or gender="女";
-- 6.查询年龄不为空的学生
select * from student where age is not null;
-- 7.查询年龄为空的学生
select * from student where age is null;
-- 8.查询年龄在15到25的人
select * from student where agr between 15 and 25;
-- 9.查询年龄为13,14,11,16的学生
select * from student where age in(13,14,11,16);
-- 10.查询年龄不为 13,15,17的学生
select * from student where age in not(13,14,17);

3,模糊查询

模糊查询关键字like。

通配符:

% (百分号)代表任意字符(0-n)

- (下划线)代表一个字符

语法格式:select * from 表名 where 列名 like "匹配格式";

匹配格式:

     1.%a%  查询函有a子母的内容

     2.刘%   查询以刘开头的内容

     3.%h     查询以h结尾的内容

     4._f%     查询第二个字母为f的内容

    


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值