zoukankan      html  css  js  c++  java
  • 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代替
    三十六般武艺,七十二般变化,修练出个人品牌并发出光芒
  • 相关阅读:
    java_day20_Servlet
    前端_day08_定位
    前端_day07_浮动和清除浮动
    前端_day06_CSS选择器
    前端_day05_HTML常见标签
    数据库_day06_多表查询,子查询,事务,sql注入
    java_day19_MVC和配置文件
    chrome更新flash player失败
    jar打包命令使用
    win7开启远程桌面服务
  • 原文地址:https://www.cnblogs.com/deeptester-vv/p/14646699.html
Copyright © 2011-2022 走看看