MYsql图形化工具基础查询,条件查询

##DQL:查询表中的记录
   *slect*from 表名;
  
  
   1.语法:
      select
        字段列表
      from
        表名列数
   where
        条件列表
   group by
        分组字段
   having
        分组之后的条件
   order by
        排序
   limit
        分页限定
 
 
 2.基础查询
     1.多个字段的查询
     select 字段名1.字段名2...from 表名;
     *注意:
         *如果查询所有字段,则可以使用*代替字段列表
  2.去除重复
     *distinct
  3.计算列
     *一般可以使用四则运算来计算一些列额值。(一般只会进行数值型的计算)
     *ifnull(表达式1,表达式2)
        *表达式1:哪个字段需要判断是否为null
     *如该字段为null后的替换值
  4.起别名
     *as:as也可以省略 打个空格就行
 3.条件查询
     1.where子句后面跟条件
  2.运算符
     *<,>,<=,>=,=,<>
     *between and
     *in(集合)
     *like:模糊查询
        *占位符:
        *-单个任意字符
     *%多个任意字符
     *is null
     *and 或&&
     *or 或||
     *not 或 |
    
          查询年龄大于20岁
    select *from student where age > 20;
    select *from student where age >= 20;
    查询年龄等于20岁
    select *from student where age = 20;
    查询年龄不等于20岁
    select *from student where age <> 20;
    select *from student where age |= 20;
    查询年龄大于等于20小于等于30
    select *from student where age >= 20; && age <=30;
    select *from student where age >= 20; and age <=30;
          select *from student where age between 20 and 30;
    查询年龄22岁,18岁,25岁的信息
    select *from student where age = 22 or age = 18 or age = 25;
    select *from student where age in (22.18,25);
    查询英语成绩为null
    select *from student where english = null;这是不对的。null值不能用= (|=)判断
    select *from student where english is null;
    
    查询英语成绩不为null
    select *from student where english is not null;
    
  

猜你喜欢

转载自www.cnblogs.com/yuanning/p/11963674.html
今日推荐