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

     

  • 相关阅读:
    [刘阳Java]_什么是MyBatis_第1讲
    [刘阳Java]_斗胆介绍一下Eclipse快捷键大全[超详细]_第6讲
    [刘阳Java]_避开环境配置快速的使用Java的开发工具_第5讲
    [刘阳Java]_JVM工作流程_第4讲
    [刘阳Java]_Java程序员的成长路线_第3讲
    [刘阳Java]_Java环境搭建_第2讲
    使用node操作mongodb
    mongodb学习
    node多文件处理方法
    yarn工具的使用
  • 原文地址:https://www.cnblogs.com/shuai0147/p/8038501.html
Copyright © 2011-2022 走看看