zoukankan      html  css  js  c++  java
  • SQl Server 函数篇 聚合函数

    说一下数据库中的聚合函数

    函数使用必须加小括号(),

    5种聚合函数:

    1、max最大值   select max(price) from car where code='c024'   --取这一列中的最大值,但是显示出的数值不属于任何列,只是一个值,但也可用作比较

    2、min最小值   select * from car where oil= (select min(price) from car)    --取这一列中的最小值

    3、avg平均值    select avg(price) as 平均价格  from car   -- 标黄的就是 其别名,因为他不属于任何列,所以可以让他显示的时候定义一个名字,也可以不用as 用空格+汉字

    4、sum求和    select sum (price) from car    

    5、count数量  select count (*) from car      -- 有多少行

    起别名:

      select avg(price) as 平均价格  from car     查询出来的列名就会变成  as 之后的名字,也可以不用as  直接空格 后面接别名

      select avg(price)  平均价格  from car   不行的话就把别名用  ' '   夹起来

      也可以用作查询  selcet *from student t   where t.id>0   别名 t 相当于  student 对象

    1.select * from car oil in (7.4,8.5,8.6)        --oil是列名

                --in 在括号里面的值都会走一遍,也就是说括号内就是条件,oil in 就是 oil 有(值)中的值

    2.select * from car oil not in (7.4,8.5,8.6)

                -- 就是不在里面,与上面说的相反

    3.select *from car where oil >=7 and oil <=8

               --  and 就是并且

    4.select * from car where oil between 7 and 8

              --   between    and     就是再两者之间,这里是 大于等于7且小于等于8

    5.select *from car where oil >any(select oil from car where code='c024' or code ='c014')

              --  any  ()  大于最小值,小于最大值( 这里就是大于括号内的任何一个值就成立,要表达的意思就是大于最小值)

    6.select * from car where oil >all(select oil from car where code='c024' or code ='c014')

              --  all ()    大于最大值,小于最小值(这里表达要大于括号内的所有值

    7. select  distinct oil  from car

         --   distinct  去重,针对某一列,不能用 *  

  • 相关阅读:
    边缘引导插值/方向卷积插值
    cout显示Mat类对象报错Access Violation
    图像特征点匹配C代码
    TF-IDF(词频-逆向文件频率)用于文字分类
    Jsp中如何通过Jsp调用Java类中的方法
    根据wsdl文件,soupUI生成webservice客户端代码
    根据wsdl,axis2工具生成客户端代码
    根据wsdl,apache cxf的wsdl2java工具生成客户端、服务端代码
    根据wsdl,基于wsimport生成代码的客户端
    Mysql截取和拆分字符串函数用法
  • 原文地址:https://www.cnblogs.com/big-lll/p/6542054.html
Copyright © 2011-2022 走看看