• 第十章 模糊查询和聚合函数


    1.什么是模糊查询?

        eg:select * from  Student  where  StudentName  like'张%'

        模糊:好像        用like关键字就是模糊查询

    2.通配符(占位符)

      (1)_:一个字符

              eg:A like 'C_'

              符合条件的值:(Ce,Cd)

        (2)%:任意字符的长度,长度可以为0

             eg:B like 'co%'

             符合条件的值:(coid,co12tf)

      (3)[ ]:指定范围内的一个值

               eg: C like'9w0[1-2]'

               符合条件的值:(9w01或9w02)

      (4)[^]:不在括号内指定范围内的一个字符

                eg:D like '9w0[^1-2]'

                符合条件的值:(9w03或9w07)

    3.like模糊查询

         eg:

                select * from  Student  where  StudentName  like'张%'

    4.查询——is null

         eg:

                select  name as 姓名,address as 地址 from  Student

                where  address  is  null or address=''

    5.回顾一下is null和''区别:

         不同:

                                 is  null                             ''

          数据类型       无数据类型                     有数据类型(字符串char,navarchar等等)

          值                  无值,真实不存在           有值但是为空

         相同:

                    都能为空

    6.between:查询特定范围内记录

                eg:

                       select  StudentId ,score from Score  where   Score between  60 and 80 

    7.IN:查询某一列中内容与所列出的内容列表是否匹配

                eg:

                      select  name  as  姓名,address  as  地址 from   Student  where  address   in(''北京','上海','广州')

    8.什么是聚合函数?

              对一组值进行计算,并返回计算机后的值,具有统计数据的作用

    9.SUM:求和

            (1)eg:

                            select SUM(score)as 总成绩 from scores  where  StudentId=23

           (2)eg:

                            SELECT SUM(Score) AS 学号23为的学生总分,CourseID AS 科目编号 FROM Score WHERE StudentID = 23

                             这个地方会爆红,因为求和后面只能放一个值,这是就用到group  by

                          需要这样写:

                                           select SUM(score)as 总成绩 from Scores where  StudentID=23

                                           group  by  CourseId

    10.AVG:求平均值

              eg:

                      select  AVG(Score)as 平均成绩 from Scores where  StudentResult>=60

    11.MAX/MIN:最大值/最小值

              eg:

                     select  Max(Score) as 最大值,Min(Score) as 最小值 from Scores  where  Score>=60

    12.Count():计数

             eg:

                     select  Count(StudentNo) as 学生人数  from  Student

            注意:count()计数可包含空值的行

                

  • 相关阅读:
    维护是关键 刻录机不读/刻盘故障实例排除
    压缩viewstate
    采用"软改"的方式激活Windows 7
    开启VAIO的VT
    比较通用的存储过程分页
    linux如何安装声卡驱动
    给Fedora11安装五笔
    导入CSV文件到数据库
    Ubuntu第一次登录用户名和密码错误不能登录
    CSS中Position、absolute、Relative、fixed、static的用法
  • 原文地址:https://www.cnblogs.com/unique1/p/12721184.html
Copyright © 2020-2023  润新知