加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

rollup分析函数

发布时间:2020-12-12 14:03:07 所属栏目:百科 来源:网络整理
导读:表的初始数据: 使用rollup进行汇总之后的数据: select t.first_name,sum(t.salary) from t_test1 t group by rollup(t.first_name) 可以改写为: select nvl(t.first_name,'total'),255);"> 使用group by实现roll up [sql] view plain copy select ta.firs

表的初始数据:

使用rollup进行汇总之后的数据:

select t.first_name,sum(t.salary)
from t_test1 t
group by rollup(t.first_name)

可以改写为:

select nvl(t.first_name,'total'),255);">

使用group by实现roll up

[sql] view plain copy
  1. selectta.first_name,sum(ta.salary)assalary
  2. fromt_test1ta
  3. groupbyta.first_name
  4. unionall
  5. select'total',147);background-color:inherit;">sum(tb.salary)fromt_test1tb


用多列rollup操作

selecttt.first_name,tt.manager_id,147);background-color:inherit;">sum(tt.salary)

  • fromt_test2tt
  • byrollup(tt.first_name,tt.manager_id)

  • 使用group by代替实现

    bytt.first_name,tt.manager_id

  • null,153);font-size:14px;border:none;">bytt.first_name
  • selectnull,153);font-size:14px;border:none;">fromt_test2tt

  • grouping的作用

    select

  • tt.first_name,
  • tt.manager_id,
  • grouping(tt.first_name),
  • grouping(tt.manager_id),
  • sum(tt.salary)
  • fromt_test2tt
  • by

  • 如果显示“1”表示GROUPING函数对应的列(例如JOB字段)是由于ROLLUP函数所产生的空值对应的信息,即对此列进行汇总计算后的结果。
    如果显示“0”表示此行对应的这列参未与ROLLUP函数分组汇总活动

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    • 推荐文章
        热点阅读