(快速入门)MySQL学习笔记一:(N运算符)

说明

这个只是本人自己学习时做的笔记,比较基础,希望大佬不喜勿喷。
有需要的小伙伴可以参考一下,只是很基础的笔记。谢谢大家!

基础的介绍

语法代码:

----------------------------------------------------
--  算数运算符
    +,-,*,/,%
    基本算数运算:通常不在条件中使用,而是用于结果运算(select字段中)
    create table ysf1(
    int_1 int,
    int_2 int,
    int_3 int,
    int_4 int)charset utf8;
    insert into ysf1(100,-100,0,null);
    select int_1 + int_2,int_2 - int_3,int_3 * int_4,int_1 /int_2,int_2 % int_3 from  ysf1;
    null进行任何运算都为null,除法中除数为0系统会给null,运算结果为浮点型数据
--  比较运算符
    >,>=,<,<=,=,<>
    通常是用来在条件中进行限定结果
    =:在mysql中,没有对应的= =比较符 ,就是用=来相等判断,<=>:相等比较
     获取年级大于18的
     select * from my_student where age>=18;
     特殊应用:就是在字段结果中进行比较运算。
     --mysql中没有规定select 必须有数据表
     select '1' <=> 1, 0.02 <=> 0;  --  如果使用=就变成了赋值。
     mysql中,数据会先自动转换成同类型,再比较,没有布尔类型,1为true,0为false;
     --between 条件1 and 条件2
     --查找年龄区间
     select * from my_student where age between 20 and 30;
     between中条件1必须小于条件2;

--  逻辑运算符
    and 逻辑与,or 逻辑或, not 逻辑非
    --查找年龄在2030之间的学生
    select * from my_student where age>=20 and age <=30;
    --查找身高高于170或者年龄大于20岁的
    select * from my_student where height>=170 or age>=20;
    --In 运算符
    在什么里面,用来替代=,结果集的时候使用
    基本语法 in(结果1,结果2...),在这个结果集中就为真。
    --查找这几个学生的信息
    select * from my_student where stu_id in('stu001','stu004','stu007');
    --is运算符
    is是专门用来判断字段是否为null的运算符
    基本语法:is null/is not null;
    --查询不为空的数据
    select * from my_int where int_4 is null;
    select * from my_int where int_4 is not null;
    --like运算符
    like运算符:是用来进行模糊匹配
    基本语法:like   '匹配模式'
    匹配模式中的两种占位符:
    _:匹配对应的单个字符
    %:匹配多个字符
    --获取所有姓小的同学
    select * from my_student where name like '小%';
    select * from my_student where name like '小_';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值