• mysql 数据库学习第二天


    查询数据(单表查询)

    查询所有列   select  * from  表名;

    查询指定列   select  字段,字段,字段 from  表名;

    查询时添加常量列   select  '新字段' as '常量名' from  表名;

    查询时合并列     select  (字段1+字段2)as '常量名' from  表名;注:合并的只能时相同类型的字段

    查询时去重复记录   select distinct  字段  from 表名;

                                   select distinct(字段)from 表名;

    条件查询    

            逻辑条件  and   or

            比较条件   >  <  >=   <=  <>  between 数值1  and  数值2

            判空条件    is  null  /  is not  null  /   ='  '   / <>'  '

             如:查询地址为空的学生(包括null和空字符串)

              null  vs   空字符串

              null    表示没有值

              空字符串   表示有值!

             如:判断null

              select * from 表名   where 字段 is null

     模糊查询   like

           %:表示任意个字符

           _: 表示一个字符

          例如:查询姓张的学生    select * from  表名  where  like ‘张%’;

                     查询姓李的  且名字是两个字的   select  * from 表名   where  like ‘李_’;

     聚合查询   sum()  avg()   max()   min()  count()

           select  sum(score) as 'score的总分' from  表名;

           select  avg(score) as 'score的平均分' from  表名;

           select  max(score) as 'score的最高分' from  表名;

           select  min(score) as 'score的最低分' from  表名;

           select  count(*)  from  表名;  查询总数

           注:count()函数统计的数量不包含null的数据

    分页查询   limit  起始行,查询几行

           总结的小规律:分页查询的数据的sql: select * from 表名 limit (当前页-1)*每页显示多少条,每页显示多少条

           如:第一页    查询第1,2条数据

             select * from  表名 limit 0,2;

                 第二页  查询第3,4条数据

              select  * from 表名  limit 2,2;

    查询排序  (order by)

          语法:order by  字段   asc/desc

          asc: 顺序,正序,递增

          desc: 倒序,逆序,递减

    分组查询  (group   by)

           如:查询男女的人数   (先分组,再统计人数)

           select  gender,count(* ) from student  group by gender;

    分组后筛选  (having)

           如:查询总人数大于3的性别  (先分组   再统计  最后加查询条件 ) 

           select  gender,count(* ) from student  group by gender  having count(*)>3;

  • 相关阅读:
    关于串口
    assigning to uiimagepickercontrollerdelegate from incompatible type
    CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 7.0'
    使用和不使用navigationbar分别处理显示和返回页面
    iphone坐标系统
    A valid provisioning profile for this executable was not found.
    Could not change executable permissions on the application
    Code Sign error: a valid provisioning profile matching the application's Identifier 'com. sensoSource.VoiceRecorder' could not be found
    从零开始开发iPhone,教你如何在真机调试iPhone应用程序
    iPhone 证书导出分享给多个开发人员操作
  • 原文地址:https://www.cnblogs.com/Java-125/p/8558883.html
Copyright © 2020-2023  润新知