原始数据:

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. P3414 SAC#1 - 组合数 题解

    https://www.luogu.org/problemnew/show/P3414(题目传送) 这道题提醒大家一定要认真审题.看清楚后发现n的数据范围稍微小于long long类型的范围(看不清被 ...

  2. sqlserver建立远程查询

    开始远程查询前: ----open:Ad Hoc Distributed QueriesEXEC sp_configure 'show advanced options',1reconfigureex ...

  3. Httpclient发送json请求

    一.Httpclient发送json请求 public String RequestJsonPost(String url){    String strresponse = null;    try ...

  4. Apicloud学习第三天——获取云数据库的数据方法

    apicloud学习30天中的对用进行注册和登录以及数据的获取的代码,在apicloud中有单独的api对用户的增删查改进行操作,这里写下增加和查询. 增加用户数据 var model=api.req ...

  5. Java反射-修改字段值, 反射修改static final修饰的字段

    反射修改字段 咱们从最简单的例子到难, 一步一步深入. 使用反射修改一个private修饰符的变量name 咱们回到主题, 先用反射来实现一个最基础的功能吧. 其中待获取的name如下: public ...

  6. 关于 Duplicate detection rules 自动 unpublish 的问题

    最近发现自己建立的 Duplicate detection rules 在 publish 之后,会不定时地变成 unpublish 的状态,经过几次测试后,发现是每次将开发中版本更新到测试的 sit ...

  7. Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes

    题目链接 题意:给你一个长度n,还有2*n-2个字符串,长度相同的字符串一个数前缀一个是后缀,让你把每个串标一下是前缀还是后缀,输出任意解即可. 思路;因为不知道前缀还是后缀所以只能搜,但可以肯定的是 ...

  8. docker安装redis

    查询镜像 docker search redis 拉取镜像 docker pull redis 启动容器 docker run --name redis -p 6379:6379 -d --resta ...

  9. day 20 - 1 序列化模块,模块的导入

    序列化模块 首先我们来看一个序列:'sdfs45sfsgerg4454287789sfsf&*0' 序列 —— 就是字符串序列化 —— 从数据类型 --> 字符串的过程反序列化 —— 从 ...

  10. vivado中如何使用chipscope

    如何使用chipscope 参考: https://www.cnblogs.com/liujinggang/p/9813863.html Xilinx FPGA开发实用教程---徐文波 田耘 1.Ch ...