zoukankan      html  css  js  c++  java
  • 日期滚动12个月统计展示

    第一行转换成第二行格式

    select b.FactoryName,
    isnull(M1,0) M1,isnull(M2,0) M2,isnull(M3,0) M3,isnull(M4,0) M4,
    isnull(M5,0) M5,isnull(M6,0) M6,isnull(M7,0) M7,isnull(M8,0) M8,
    isnull(M9,0) M9,isnull(M10,0) M10,isnull(M11,0) M11,isnull(M11,0) M12,
    b.Month1,b.Month2,b.Month3,b.Month4,
    b.Month5,b.Month6,b.Month7,b.Month8,
    b.Month9,b.Month10,b.Month11,b.Month12
    from(
    select FactoryName,
    sum(case datediff(m,getdate(),DateId+'01') when 0 then number else 0 end) M1,
    sum(case datediff(m,getdate(),DateId+'01') when 1 then number else 0 end) M2,
    sum(case datediff(m,getdate(),DateId+'01') when 2 then number else 0 end) M3,
    sum(case datediff(m,getdate(),DateId+'01') when 3 then number else 0 end) M4,
    sum(case datediff(m,getdate(),DateId+'01') when 4 then number else 0 end) M5,
    sum(case datediff(m,getdate(),DateId+'01') when 5 then number else 0 end) M6,
    sum(case datediff(m,getdate(),DateId+'01') when 6 then number else 0 end) M7,
    sum(case datediff(m,getdate(),DateId+'01') when 7 then number else 0 end) M8,
    sum(case datediff(m,getdate(),DateId+'01') when 8 then number else 0 end) M9,
    sum(case datediff(m,getdate(),DateId+'01') when 9 then number else 0 end) M10,
    sum(case datediff(m,getdate(),DateId+'01') when 10 then number else 0 end) M11,
    sum(case datediff(m,getdate(),DateId+'01') when 11 then number else 0 end) M12
    from cmdi_MonitorBaseData_Detail_Sum_Bar
    group by FactoryName
    )a
    full join(
    select aa.*,bb.FactoryName from(
    select convert(varchar(7),getdate(),120) Month1,
    convert(varchar(7),dateadd(m,1,getdate()),120) Month2,
    convert(varchar(7),dateadd(m,2,getdate()),120) Month3,
    convert(varchar(7),dateadd(m,3,getdate()),120) Month4,
    convert(varchar(7),dateadd(m,4,getdate()),120) Month5,
    convert(varchar(7),dateadd(m,5,getdate()),120) Month6,
    convert(varchar(7),dateadd(m,6,getdate()),120) Month7,
    convert(varchar(7),dateadd(m,7,getdate()),120) Month8,
    convert(varchar(7),dateadd(m,8,getdate()),120) Month9,
    convert(varchar(7),dateadd(m,9,getdate()),120) Month10,
    convert(varchar(7),dateadd(m,10,getdate()),120) Month11,
    convert(varchar(7),dateadd(m,11,getdate()),120) Month12
    )aa
    cross join(
    select '达创' FactoryName
    union all
    select 'H3C' FactoryName
    union all
    select '飞旭' FactoryName
    union all
    select '统合' FactoryName
    union all
    select '信华' FactoryName
    union all
    select '东信' FactoryName
    union all
    select '杭州贝赢' FactoryName
    )bb
    )b on a.FactoryName=b.FactoryName

     

  • 相关阅读:
    列式存储hbase系统架构学习
    使用Phoenix通过sql语句更新操作hbase数据
    分布式实时日志系统(四) 环境搭建之centos 6.4下hbase 1.0.1 分布式集群搭建
    布式实时日志系统(三) 环境搭建之centos 6.4下hadoop 2.5.2完全分布式集群搭建最全资料
    GDI+绘制五星红旗
    C#模拟登录后请求查询
    ubuntu下安装mysql
    配置nginx实现windows/iis应用负载均衡
    23种设计模式之原型模式(Prototype)
    23种设计模式之访问者模式(Visitor)
  • 原文地址:https://www.cnblogs.com/shuai0147/p/8038501.html
Copyright © 2011-2022 走看看