原始数据:

01 RD21 6495.4114
02 RD21 87.436
04 RD21 101.7184
05 RD21 1.5384
01 RD25 7803.3037
09 RD25 106.8375
01 RD33 20036.4738
02 RD33 2179.80
03 RD33 159.6858
05 RD33 83.8036
06 RD33 82.59
07 RD33 290.24
08 RD33 560.1575
09 RD33 0.00

select c.*,a.amountmoney from (
select rdno,
max(case mondate when '01' then amount else 0 end) as "01",
max(case mondate when '02' then amount else 0 end) as "02",
max(case mondate when '03' then amount else 0 end) as "03",
max(case mondate when '04' then amount else 0 end) as "04",
max(case mondate when '05' then amount else 0 end) as "05",
max(case mondate when '06' then amount else 0 end) as "06",
max(case mondate when '07' then amount else 0 end) as "07",
max(case mondate when '08' then amount else 0 end) as "08",
max(case mondate when '09' then amount else 0 end) as "09",
max(case mondate when '10' then amount else 0 end) as "10",
max(case mondate when '11' then amount else 0 end) as "11",
max(case mondate when '12' then amount else 0 end) as "12"
from ( select datename(mm,operdate) as mondate,rdno,sum(summoney) as amount
from fp_pr_materialdetail with(nolock)
where operdate<='2018-12-31' and operdate>='2018-01-01'
group by datename(mm,operdate),rdno
) b group by rdno) c
left join (select rdno,sum(amount) as amountmoney from (
select rdno,sum(summoney) as amount
from fp_pr_materialdetail with(nolock)
where operdate<='2018-12-31' and operdate>='2018-01-01'
group by rdno
) k group by rdno) a on a.rdno=c.rdno

结果数据:

RDno 01       02       03     04       05       06    07     08     09     10  11   12

RD21 6495.4114 87.436 0.00 101.7184 1.5384 0.00 0.00 0.00 0.00 0.00 0.00 0.00 6686.1042
RD25 7803.3037 0.00 0.00 0.00 0.00 0.00 0.00 0.00 106.8375 0.00 0.00 0.00 7910.1412
RD33 20036.4738 2179.80 159.6858 0.00 83.8036 82.59 290.24 560.1575 0.00 0.00 0.00 0.00 23392.7507

sql server按月份,按项目号展开表格的更多相关文章

  1. 采用Opserver来监控你的ASP.NET项目系列(二、监控SQL Server与Asp.Net项目)

    前言 之前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也可以看看. 今天我们主要来介绍一下,如何使用Opserver监控我们的SQL Server 和ASP.NET项目的异常监控 ...

  2. SQL Server 2008 删除数据库帐号失败问题

    SQL Server 2008 中单独为一个项目建立了一个账号zdhsa,结果发现无法删除. 问题:删除zdhsa失败. 解决:首先从"安全性"-"架构"中删除 ...

  3. SQL Server附加数据库失败错误号:5120的解决办法

    附加数据库时出现附加数据库失败的错误,错误号是5120,已经两次遇到这种问题了.今天写一下解决办法. 有两个方法,很简单: 1.设置mdf文件所在文件夹的权限,在文件夹上右击——属性——安全,如图所示 ...

  4. SQL Server 存储过程自定义生成ID号

    * FROM sys.tables WHERE name=N'EmployeeNo_Identity') DROP TABLE EmployeeNo_Identity GO CREATE TABLE ...

  5. 【SQL server基础】手动创建数据库和表格

    use master go if exists(select * from sysdatabases where name='learning') drop database learning go ...

  6. VS 2017 Web项目需要安装Sql Server 2012 Express LocalDB问题

    最近在做mvc5的练习 ,结果到了数据库连接这一阶段就出现了问题,开始我以为<add name="MovieDBContext" connectionString=" ...

  7. 项目升级-oracle改版sql server问题点汇总

    目录 1.符号使用 1.1 :->@ 1.2 mod()->% 1.3 ||->+ 1.4 off等表别名 1.5 columnnum=1->top 1 1.6 minus-& ...

  8. SQL SERVER 作业浅析

    作业介绍 SQL SERVER的作业是一系列由SQL SERVER代理按顺序执行的指定操作.作业可以执行一系列活动,包括运行Transact-SQL脚本.命令行应用程序.Microsoft Activ ...

  9. Sql Server使用正则表达式

    近日因项目需求,需要在sql server中用到正则表达式,因Sql Server本身并不支持正则表达式,需要用到Clr函数. 在此记录一下步骤,与大家共享,虽然写的是原创,但有参考网上的文章. 1. ...

随机推荐

  1. application对象的应用案例

    application对象由多个客户端用户共享,它的应用范围是所有的客户,服务器启动后,新建一个application对象,该对象一旦建立,就一直保持到服务器关闭.当有客户访问服务器上的一个JSP页面 ...

  2. app开发中的经常遇到的问题

    1.banner不显示: 原因:配置文件中的 域名写错了. img_path = https://www.beicaiduo.com/znbsite/static/tinymce/upload/ 解决 ...

  3. JS学习笔记Day24

    一.闭包和函数 (一)什么是闭包函数 概念:简单说就是函数中嵌套函数,嵌套在这里面的函数叫做闭包函数,外面的函数叫做闭包环境 作用:通过闭包函数,可以访问到闭包函数所在局部作用域中的变量及参数 特点: ...

  4. spring Boot 入门--为什么用spring boot

    为什么用spring boot 回答这个问题不得不说下spring 假设你受命用Spring开发一个简单的Hello World Web应用程序.你该做什么? 我能想到一些 基本的需要.  一个项目 ...

  5. 安装redis服务

    wget http://download.redis.io/releases/redis-3.2.6.tar.gz tar -zxvf redis-3.2.6.tar.gzcd redis-3.2.6 ...

  6. javaWeb使用百度编辑器上传图片的问题

    1.先看项目结构(访问网站:http://localhost:8080/baidu_edit/) 2.部署6个jar包 1)先将jsp/lib的6个jar包放入到WEB-INF/lib文件夹中 2)然 ...

  7. LeetCode-11. 盛最多水的容器

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  8. metasploit与Cobaltstrike互相派生shell

    msf 派生 shell 给 Cobalt strike(前提有一个meterpreter) msf exploit(handler) > use exploit/windows/local/p ...

  9. HttpServletRequest基础

    一.请求行 二.请求消息头 三.请求正文(重要) 1.获取表单(request)提交的数据 (1)getParameter(name):根据表单name属性的名字,获取name的值 (2)getPar ...

  10. junit测试

    /**ssm框架测试service**/ import com.alibaba.fastjson.JSON; import com.raycloud.waimai.customer.center.po ...