zoukankan      html  css  js  c++  java
  • oracle数据库查询出多条数据,合并,之后列转行

    select B.enterprise_code,
    B.enterprise_name,
    sum(B.h0_overnum) AS over00,
    sum(B.h1_overnum) AS over01,
    sum(B.h2_overnum) AS over02,
    sum(B.h3_overnum) AS over03,
    sum(B.h4_overnum) AS over04,
    sum(B.h5_overnum) AS over05,
    sum(B.h6_overnum) AS over06,
    sum(B.h7_overnum) AS over07,
    sum(B.h8_overnum) AS over08,
    sum(B.h9_overnum) AS over09,
    sum(B.h10_overnum) AS over10,
    sum(B.h11_overnum) AS over11,
    sum(B.h12_overnum) AS over12
    from table B
    where B.monitor_time = to_char(sysdate - 1, 'yyyy-mm-dd')
    group by B.enterprise_code,B.enterprise_name

    合并用sum,统计个数用count。

    之后列转行

    select enterprise_code, enterprise_name, OVERNUM, MONITOR_TIME
    from (select B.enterprise_code,
    B.enterprise_name,
    sum(B.h0_overnum) AS over00,
    sum(B.h1_overnum) AS over01,
    sum(B.h2_overnum) AS over02,
    sum(B.h3_overnum) AS over03,
    sum(B.h4_overnum) AS over04,
    sum(B.h5_overnum) AS over05,
    sum(B.h6_overnum) AS over06,
    sum(B.h7_overnum) AS over07,
    sum(B.h8_overnum) AS over08,
    sum(B.h9_overnum) AS over09,
    sum(B.h10_overnum) AS over10,
    sum(B.h11_overnum) AS over11,
    sum(B.h12_overnum) AS over12
    from table B
    where B.monitor_time = to_char(sysdate - 1, 'yyyy-mm-dd')
    group by B.enterprise_code,B.enterprise_name) A unpivot(OVERNUM for MONITOR_TIME in(over00,
    over01,
    over02,
    over03,
    over04,
    over05,
    over06,
    over07,
    over08,
    over09,
    over10,
    over11,
    over12))

  • 相关阅读:
    java 反射 处理 空值
    jquery之data()
    jquery里面的$.each()方法
    Normalize.css 样式作用,及使用方法
    robots.txt、humans.txt、.editorconfig、.gitignore、LICENSE.txt、README.md、CHANGLOG.md
    常见的js算法
    javascript设计模式详解
    ES6的相关信息
    轮播图插件
    webstrom随手笔记
  • 原文地址:https://www.cnblogs.com/webttt/p/8026144.html
Copyright © 2011-2022 走看看