zoukankan      html  css  js  c++  java
  • oracle的sql 记录

    ----1.分组函数--
    select max(tfi.expected_scale) max1,
    min(tfi.expected_scale) min1,
    to_char(avg(tfi.expected_scale), '9,999,999,999,990.99999') avg1 ---小数点后几位
    from t_fund_info tfi
    --2.查询日期类型的数据
    select tt.last_modify_time, tt.*
    from t_fund_info tt
    where to_char(tt.last_modify_time, 'yyyy-mm-dd') >= '2016-03-01'

    select tt.last_modify_time, tt.*
    from t_fund_info tt
    where tt.last_modify_time >= to_date('2016-03-01', 'yyyy-mm-dd')
    ----3.select 的执行顺序
    from -> where -> group by -> having -> select - order by
    select max(tt.expected_scale) max1, tt.fund_code
    from t_fund_info tt
    where tt.last_modify_time >= to_date('2016-03-01', 'yyyy-mm-dd')
    group by tt.fund_code
    having avg(tt.expected_scale) > 1000
    order by avg(tt.expected_scale) desc;
    -----4.按入职年份和部门进行统计,查询出各部门各入职年份的最高工资和最低工资,多列统计
    select to_char(hiredate,'yyyy'),deptno,max(sal),min(sal) from emp group by to_char(hiredate,'yyyy'),deptno; 
    ----分组查询时注意:
    1.带group by的分组查询,执行顺序是先分组group by 后查询 select,即,写在select 后面的列,必须是分组列,或 组函数
    2.where条件中不能直接使用组函数
    3.分组数据可以使用having字句进行过滤
    4.分组列可以不在select子句中显示,select 列中要显示的列,必须出现在group by 分组中(在select 子句中非组函数列,都必须添加到group by 中)
    5.having 是对group by分组后的数据进行过滤
    6.组查询语句可以使用在:select ,having ,order by 。不能直接使用在

  • 相关阅读:
    centos 6.4 FTP安装和配置
    常用正则表达式集锦
    同一服务器部署多个tomcat时的端口号修改详情
    介绍linux下vi命令的使用
    CentOS下安装两个或多个Tomcat7
    tomcat解析之简单web服务器(图)
    吻你
    用C++语言开发Android程序 配置开发环境
    内地开源镜像网站
    Android SDK Android NDK Android Studio 官方下载地址
  • 原文地址:https://www.cnblogs.com/xiaofuzi123456/p/11239995.html
Copyright © 2011-2022 走看看