zoukankan      html  css  js  c++  java
  • 2014/11/25 函数

    一、聚合函数(Aggregate Functions)
    AVG:求平均 
    count:计算个数 
    MAX:最大值
    MIN:最小值
    SUM:求和

    例:select count(*) as 人数 from student--as 人数,列名显示为“人数”
    select(select count (*) from student where sex='男')-count(*) from student……
    --用“-”号相连,计算两条语句计算后的数值差

    select count(*),avg(height),class from student group by class having count(*)>6
    --查询每班的个数和平均身高
    --“having count(*)>6”表示将count计算大于6的筛选(显示)出来

    select * from student as a where height>(select avg(height)from student as b where b.class=a.class)
    --查询每个班里比这个班的平均身高高的同学的所有信息
    --当信息重合时,需为重合的信息自己指定其他的名字与其区分开

    二、数学函数(Mathematial Functions)
    ABS:取绝对值
    ceiling:天花板(向上取整)  例:1.2345=2
    floor:地板(向下取整)      例:1.3456=1
    PI:圆周率                   select PI()=3.141592653
    Round:四舍五入              select Round(3.567,2)=3.570
    Rand:随机
    sqrt:平方根
    square:平方

    print--输出到消息框

    三、日期时间函数
    select dateadd(year,1,'1990-09-09')--year为单位,1为添加数量,最后为添加到什么地方
    select dateadd(month,1,'2014-03-31')

    datediff:取时间差
    例:select datediff(year,'2011-12-31','2014-01-01')--结果为3

    datename:到某个时间为止,是今天年的第几年(月日)
    例:select datename (week,'2014-11-25')--结果为“48”
        select datename(weekday,'2014-11-25')--结果为“星期二”
    返回的为字符型数值

    datepart:用法与datename一致,但返回的为整数型数值
    day:返回一个整数,表示为该月份的哪一天
    getdate:返回一个日期,该日期为数据库的时间
    isdate:判断一个日期时间是否正确
    sysdate:返回一个日期,该日期为本地电脑的时间

  • 相关阅读:
    scnner02 (nextLine)
    Scanner01
    Spring 框架 (初学)
    查询自己写了多少行代码
    jdbc事务
    jdbc(预编译插入数据)
    jdbc(java连接数据库)
    监听器扩展
    listener(监听器)
    Filter过滤器
  • 原文地址:https://www.cnblogs.com/jintuo/p/4121772.html
Copyright © 2011-2022 走看看