zoukankan      html  css  js  c++  java
  • 20141125

      -聚合函数 (1)count(*)求个数 (2)avg(*)求平均数 (3)max(*)求最大值 (4)min(*)求最小值 (5)sum(*)求和 (1)select(select COUNT(*) from student where sex='男'and classcode='20050102')-COUNT(*) from student where sex='男'and classcode='20050101'--二班男生比一班男生多多少   select 5-COUNT(*) from student where sex='男'and classcode='20050101'  --表达同样的意思 select AVG(stature) as 平均身高,COUNT(*) as 人数 from student where sex='女'--女生的平均身高和人数 select* from student where stature>(select avg(stature) from student) --查询比平均身高高的学生信息 select* from student where classcode='20050102'and stature>(select avg (stature)from student where classcode='20050102')--查询二班比平均身高高的学生信息 --结合分组使用聚合函数,分别每组计算显示having筛选 select COUNT(*),AVG(stature),classcode from student group by classcode-- 按班级分组各有多少人和平均身高 select count(*),avg(stature),classcode from student group by classcode having avg(stature) >166--查询每个班的人数,并且平均身高大于166的班级,按班级分类 select COUNT(*),avg(stature),classcode from student where sex='男'group by classcode 查每个班里男生的个数和平均身高 select * from student as a where stature>(select AVG(stature) from student as b where b.classcode=a.classcode)--每个班里比这个班平均身高高的同学的信息   数学函数 (1)abs取绝对值 select  ABS(-1)--绝对值 (2)ceiling上限取整 select CEILING(1.4) (3)floor下线取整 select FLOOR(1.9) (4)PI圆周率 SELECT PI()=圆周率 (5)round第一个参数是要进行四舍五入的数,第二个参数是要四舍五入到第几位 select ROUND(3.567,2)四舍五入 select ROUND(3.564,2) (6)rand()随机生成 select RAND() (7)sqrt求平方根 select SQRT(16) (8)SQUARE()平方 SELECT SQUARE(2) select top 5 SQRT(stature) from student order by stature desc--最高的五个身高取平方根 select*from student where ceiling (SQRT(stature))=14--身高天花板平方根之后等于14的同学的信息 (9)print输出到消息框 print'你好' print ceiling(1.2) 日期时间函数 (1)DATEADD自动添加时间 --select dateadd (year,1,'1990/09/09') --select dateadd(year,1,'2000/2/29') --select dateadd(month,1,'2014/3/31') (2)datediff取时间差,反过来为负数 select DATEDIFF(year,'2011/09/22','2014/01/01') select datediff(month,'2012/12/31','2013/1/1') select datediff(month,'2014/12/31','2013/1/1') select datediff(week,'2012/12/31','2013/1/1') (3)datename单独返回某个日期的时间中的年月日时分秒,或星期几 select DATENAME(year,'2014/11/25') select DATENAME(week,'2014/11/25') select DATENAME(weekday,'2014/11/25') (4)datepart select DAtepart(year,'2014/11/25') select DATEpart(week,'2014/11/25') select DATEpart(weekday,'2014/11/25') (5)day select DAY ('2014/11/25') (6)getdate返回当前服务时间 select GETDATE() select SYSDATETIME() (7)isdate判断一个日期时间是不是正确 select ISDATE ('2014/2/28') 找出1985年出生的人的信息 select*from student where YEAR(birthday)=1985

  • 相关阅读:
    (双指针 二分) leetcode 167. Two Sum II
    (双指针) leetcode 485. Max Consecutive Ones
    (双指针) leetcode 27. Remove Element
    (String) leetcode 67. Add Binary
    (数组) leetcode 66. Plus One
    (N叉树 BFS) leetcode429. N-ary Tree Level Order Traversal
    (N叉树 递归) leetcode 590. N-ary Tree Postorder Traversal
    (N叉树 递归) leetcode589. N-ary Tree Preorder Traversal
    (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree
    (BST 递归) leetcode98. Validate Binary Search Tree
  • 原文地址:https://www.cnblogs.com/577521a/p/4125554.html
Copyright © 2011-2022 走看看