zoukankan      html  css  js  c++  java
  • Mysql单表查询

    单表查询

    1. 指定查询

    -- 查询1001信息?
      select * from user where 1001

    2. 带in关键字查询

    -- 查询1001、1004、1009 三个人信息?
      select * from user where id = 1001 or id = 1004 or id = 1009;

    3. Between And 两者之间【包含两端的值】

    -- 查询成绩在73 ~82之前的学生的姓名
      select name from user where grade >=73 and grade <=82;
      select name from user where grade between 73 and 82;[推荐]

    4. not Between And 不在两者之间

    -- 查询编号不在1008~1016 之间的学生的姓名
      select name from user where id <1008 and id >1016;
      select name from user where id not between 1008 and 1016; [推荐]

    5. 空值查询

    -- 查询user表中成绩为空的用户信息?
      select * from user where grade is null;

    6. 不为空值查询

    -- 查询user表中成绩不为空的用户信息?
      select * from user where grade is not null;

    7. 去重复查询[distinct] distinct 必须紧跟着select

    -- 查询user表中的用户,去除重复name
      select distinct name from user;

    8. 模糊查询 - like

    -- 查询user表中姓名的开头姓周?
      select * from user where name like "周%";
    • % 百分号 : 通配符
      •   含义: 可以代替 任意长度、任意内容。
    • _下划线: 占位符
      • 含义:可以代替任意内容,一个(下划线代表一个)长度
    -- 查询user表中姓名中含有星字?
      select * from user where name like "%星%";
    -- 查询user表中姓名中以范字开头、冰字结束?
      select * from user where name like "范%冰";
    -- 查询user表中姓名有三个字,末尾是华?
      select * from user where name like "__华";
    -- 查询user表中姓名有%的用户?
      select * from user where name like "%\%%"; -- | 反转字符
  • 相关阅读:
    从面向对象到SOA
    我对国内软件开发类书籍出版与写作的体会与努力
    MSDN for 2010的那些麻烦事
    金旭亮新作《.NET 4.0面向对象编程漫谈》之序“穿越梦想、起锚远航”
    Silverlight应用程序的本地通讯
    C#中Dictionary的用法
    泛型
    动态规划算法
    C# Timer
    面向对象程序设计寒假作业1
  • 原文地址:https://www.cnblogs.com/wangjixue/p/11592619.html
Copyright © 2011-2022 走看看