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

     

  • 相关阅读:
    python中获取python版本号的方法
    Unity3D 的大场景内存优化
    Unity中的内存泄漏
    HDR和bloom效果的区别和关系
    用TexturePacker打图集用于UGUI中
    Lua的闭包详解(终于搞懂了)
    深入浅出!从语义角度分析隐藏在Unity协程背后的原理
    Unity3D导入3DMax模型缩放单位问题深入分析
    Unite 2017 | 从《闹闹天宫》看MOBA游戏里的网络同步技术
    Unity声音-音源组件
  • 原文地址:https://www.cnblogs.com/shuai0147/p/8038501.html
Copyright © 2011-2022 走看看