oracle各种指令(上课笔记)(二)

2014-11-24 15:21:26 · 作者: · 浏览: 1
r from d) year month day hour minute second select extract(year from sysdate) from dual; (7) last_day(d)得到日期中最后一天 (8) next_day();下一个工作日 (9) round :对日期四舍五入 (10)trunc :对日期截取 year month ,day select round(sysdate,'month') from dual; select trunc(sysdate,'month') from dual; yyyy 年 mm 月 dd 日 hh hh24 mi ss $ 表示美元 L 本地货币的表示 , 数值之间的分隔 . 小数分隔 9 表示数值 0 表示小数位 (4) 转换函数 to_char(c,format) select to_char(sysdate,'dd') from dual; select to_char(123456,'$999,999.99') from dual; $123,456 to_date('今天是2013年','"今天是"yyyy"年"') from dual; to_number() (5) 其它函数 nvl() decode(); if else if else if select decode(job,'CLERK',sal,'MANAGER',sal*1.2) from emp;

9.分组函数
  count()  个数
  sum()    求和
  avg()    平均值
  max()    最大值 
  min()    最小值
  (1)各个部门的成员人数
  group by 分组
  select count(empno) from emp group by deptno;
  
  select deptno ,count(empno) from emp group by deptno;
  (2)得到每个部门的平均工资 
  select avg(sal) from emp group by deptno;
     得到除了10号部门的平均工资
  select deptno,avg(sal) from emp where deptno not in(10) group by deptno;
  select deptno,avg(sal) from emp where avg(sal) >=2000 group by deptno;


  (3) select deptno,avg(sal) from emp where deptno not in(10) group by deptno having avg(sal)>=800 order by avg(sal) asc; 
      1.where 过滤   一些记录
      2.group by 分组 第二次记录
      3.分组后的过滤 having  第三次记录
      4.order by 排序