• 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 。不能直接使用在

  • 相关阅读:
    Fody is only supported on MSBuild 16 and above
    abp发送邮件AbpMailKit
    看一位老司机的博文,分享一下。
    nginx PC 移动配置
    微信开放平台登录
    flask 中 session的源码解析
    python mac环境搭建
    前端换mac可以参考搭一下简单的环境
    vue 导航钩子
    HTML5 History 模式
  • 原文地址:https://www.cnblogs.com/xiaofuzi123456/p/11239995.html
Copyright © 2020-2023  润新知