zoukankan      html  css  js  c++  java
  • 运算符

    /*一、运算符
    1、算术运算符
    +:加
    -:减
    *:乘
    /:除   可以保留小数部分
    div:除  如果整数与整数相除只保留整数部分
    %:求余数
    mod:求余数
    */
    select 1/2; #0.5
    select 1 div 2; #0
    
    /*
    2、比较运算符
    >:大于
    <:小于
    =:等于  注意区别,Java中是==,mysql中是=
    >=:大于等于
    <=:小于等于
    !=:不等于
    <>:不等于
    <=>:安全等于  用于判断null值的比较运算符
            null值的判断,习惯上我们用is null 和is not null
    */
    #查询薪资大于20000元的员工
    select * from t_employee where salary > 20000;
    
    #查询所有男员工
    select * from t_employee where gender = '男';
    select * from t_employee where gender != '女';
    select * from t_employee where gender <> '女';
    
    #查询奖金比例commision_pct是null的员工
    select  * from t_employee where commission_pct <=> null;
    select  * from t_employee where commission_pct is null;
    
    /*
    3、逻辑运算符
    &&和and:逻辑与
        两个条件同时满足
    ||和or:逻辑或
        两个条件满足任意一个
    ^和xor:逻辑异或
        两个条件只能满足其中一个
    !和not:
        不满足xx条件
        */
    #查询薪资大于20000元的女员工    
    select * from t_employee where salary > 20000 && gender = '女';
    select * from t_employee where salary > 20000 and gender = '女';
    
    #查询男员工
    select * from t_employee where not gender = '女';
    select * from t_employee where !(gender = '女');
    
    #查询薪资大于10000  异或 性别是男的,即它俩只能满足一个
    #即查询薪资大于10000的女的或薪资低于10000的男的
    select * from t_employee where salary>10000 ^ gender ='男';
    select * from t_employee where salary>10000 xor gender ='男';
    /*
    4、范围
    (1)区间范围:
        在[a,b]之间,between a and b
        不在[a,b]之间,not between a and b
    (2)集合范围
        in(...)
        not in(...)
    */
    #查询薪资在[15000,20000]之间的员工
    select * from t_employee where salary between 15000 and 20000;
    select * from t_employee where salary >= 15000 and salary <=20000;
    
    #查询薪资在9000,10000,12000
    select * from t_employee where salary in(9000,10000,12000);
    select * from t_employee where salary =9000 || salary =10000 || salary =12000;
     /*
    5、模糊查询
    like '%x%' x代表确定的字符 %表示不确定的0~n个字符
         '_x%'  x代表确定的字符 _表示确定的1个字符
    */
    #查询,名字ename中包含“冰”这个字的员工
    select * from t_employee where ename like '%冰%';
    
    #查询,名字ename是张xx,三个字
    select * from t_employee where ename like '张__';
    
    #查询,名字ename是第二个字是'冰'
    select * from t_employee where ename like '_冰%';
  • 相关阅读:
    NetworkManager——Linux强大的网络管理工具
    linux 添加用户、权限
    打造坚固的安全的Linux服务器(ssh登录篇)
    liunx下NetworkManager导致网卡不能启动
    Linux: service network/Network/NetworkManager
    linux里的bootproto的none,static,dhcp有什么区别
    swift protocol的几种形式
    函数式编程编程即高阶函数+monad
    泛型理论及抽象方向
    类型与函数的结合性:给类型添加函数?
  • 原文地址:https://www.cnblogs.com/xp20170618/p/14046453.html
Copyright © 2011-2022 走看看