• MySQL之模糊查询


    --like:一般和通配符搭配使用
    --通配符 % :任意多个字符,包含0个字符
    案例1:查询员工名中包含字符a的员工信息
    select * from employees where like '%a%'; --包含abc
    
    案例2:查询员工名中第三个字符为e,第五个字符为a的员工名和工资
    select last_name,salary from employees where last_name like '__e_a%';
    
    案例3:查询员工名中第二个字符为_的员工名
    select last_name from employees where last_name like '_$_%' ESCAPE '$'; --ESCAPE为转译,后面符号随意指定
    
    --between and 1、可以提高语句的简洁度 2、包含临界值
    
    --in 判断某字段的值是否属于in列表中的某一项,特点:1、使用in提高语句简洁度 2、In中的字符类型需一致或兼容
    
    案例1:查询工种编号是IT_PROG ,AD_VP,AD_PRES中的一个员工名和工种编号
    select last_name,job_id from employees where job_id='IT_PROG' or job_id='AD_VP' or job_id='AD_PRES';
    等同于以下
    select last_name,job_id from employees where job_id IN('IT_PROG','AD_VP','AD_PRES');
    
    
    --is null 
    案例1:select last_name,commission_pct from employees where commission_pct is null --奖金为空的员工姓名和奖金金额
    案例2:select last_name,commission_pct from employees where commission_pct is not    null; --奖金不为空的员工姓名和奖金金额
    
    --安全等于:<=>
    案例1:select last_name,commission_pct from employees where commission_pct <=> null --奖金为空的员工姓名和奖金金额 缺点:可读性不好
    
    --IFNULL: IFNULL(name,0)表示如果name这个字段是null时,就用0代替
    三十六般武艺,七十二般变化,修练出个人品牌并发出光芒
  • 相关阅读:
    Gym
    Gym 100712H
    CodeForces
    CodeForces
    P1103 书本整理(DP)
    P1435 回文子串(最长公共子序列)
    P1095 守望者的逃离(线性DP)
    P1077 摆花(背包)
    P1832 A+B Problem(再升级)
    P1757 通天之分组背包(分组背包)
  • 原文地址:https://www.cnblogs.com/deeptester-vv/p/14646699.html
Copyright © 2020-2023  润新知