MySQL 3 DQL


DQL 数据查询语言

    所有查询操作都要用  Select

    简单的查询  复杂的查询都用它

     最核心频率最高的软件

    查询全部的学生      Select  字段和学生表   

               Select  * FROM     student

   查询指定字段 

              select   ’studentNo',From  student

  ----别名   给结果起一个别名    可以给字段也可以给表起

 select  studentname  AS 学生姓名  from    student

语法:select 字段。。。from  表

有时候  列名字不是见名旨意     我们起别名   字段名  as  新名字     

去重复:

       distinct

查询一下有哪些同学参加了考试  ,成绩

select * from  reslut  查询全部成绩

select ‘studentNot'  from result 

select distinct ‘studentNO’from result    发现全部数据  去重

select  version() 查询系统版本

select  100*3-1 AS 计算结果   --用来计算

select    ’studentNo','StudentResult‘+1  AS”提分后“  from  result

数据库中的表达式  :文本值,列, null,函数,计算表达式,系统变量

          select   表达式   from  表

where  条件子句

               检索数据中符合条件的值

             搜索的条件有一个或多个表达式  组成  与或非           

          select  studentno,studentresult   from  result

          where studentresult>=95&& studentTesult<=100

   模糊查询(区间)

        select  studentno,studentresult   from  result

     where    studentresult  between  95 and  100

--------除了1000号以外的学生信息

       select  studentno,studentresult   from  result

       where  studentresult   != 1000;    where not   studentresult   = 1000;

       

模糊查询   :比较运算符

 ---------------模糊查询-------------------------------

查询姓刘的同学     like结合  %表示0到任意一个字符    —一个字符

select    studentno,studentname  from  student

where   studentname     like’刘%'

-------查询姓刘的同学,后面只有一个字的

     select  studentno,studentname from student

    where   student   like  ’刘_'

-------查询姓刘的同学,后面只有两个字的

  select  studentno,studentname from student

    where   student   like  ’刘__'

 -----查询中间有嘉字的同学    &嘉%

  where   student   like  ’%刘%'

-------------------in--------------------------------

--查询 1001  1002 1003学员

    Select studentno,studentname  from  student

    where    studentno  in (1001,1002,1003);

-------  null   not   null--------------

查询地址为空的

select   studentno  from   student

where address=‘’ or address is  null

where  address is  not  null

联表查询:

左表  leftjoin       innerjoin    rightjoin

--------联表查询     join-----------------

查询参加考试的同学(学号,姓名,科目编号,分数)

select  *  from  student

select* from   result

/*思路

      1.分析需求,分析字段来自那个表

      2.分析哪种查询  7种

          确定交叉点      (两个表数据是相同的)

        判断条件:这两个学生表中的  studentno=成绩表    studentno

    select  studentno,studentname,subjectno,studentresult

    from   student   as   s

     inner  join   result   as  r

    where  s.studentno=r.studentno

---------join (连接的表) on(判断条件) 链接查询      where  等值查询

           

  -------------自链接--------------------------

自己和自己的表链接     一张表拆成两个表

分页和排序

=================分页limit 和排序  order  by================

升序ASC    降序DESC

----通过哪个字段排序  怎末排

------查询结果   成绩降低

为什么分页?减轻数据库压力    给人好的效果   现在是瀑布流