sql server按月份,按项目号展开表格
原始数据:
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按月份,按项目号展开表格的更多相关文章
- 采用Opserver来监控你的ASP.NET项目系列(二、监控SQL Server与Asp.Net项目)
前言 之前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也可以看看. 今天我们主要来介绍一下,如何使用Opserver监控我们的SQL Server 和ASP.NET项目的异常监控 ...
- SQL Server 2008 删除数据库帐号失败问题
SQL Server 2008 中单独为一个项目建立了一个账号zdhsa,结果发现无法删除. 问题:删除zdhsa失败. 解决:首先从"安全性"-"架构"中删除 ...
- SQL Server附加数据库失败错误号:5120的解决办法
附加数据库时出现附加数据库失败的错误,错误号是5120,已经两次遇到这种问题了.今天写一下解决办法. 有两个方法,很简单: 1.设置mdf文件所在文件夹的权限,在文件夹上右击——属性——安全,如图所示 ...
- SQL Server 存储过程自定义生成ID号
* FROM sys.tables WHERE name=N'EmployeeNo_Identity') DROP TABLE EmployeeNo_Identity GO CREATE TABLE ...
- 【SQL server基础】手动创建数据库和表格
use master go if exists(select * from sysdatabases where name='learning') drop database learning go ...
- VS 2017 Web项目需要安装Sql Server 2012 Express LocalDB问题
最近在做mvc5的练习 ,结果到了数据库连接这一阶段就出现了问题,开始我以为<add name="MovieDBContext" connectionString=" ...
- 项目升级-oracle改版sql server问题点汇总
目录 1.符号使用 1.1 :->@ 1.2 mod()->% 1.3 ||->+ 1.4 off等表别名 1.5 columnnum=1->top 1 1.6 minus-& ...
- SQL SERVER 作业浅析
作业介绍 SQL SERVER的作业是一系列由SQL SERVER代理按顺序执行的指定操作.作业可以执行一系列活动,包括运行Transact-SQL脚本.命令行应用程序.Microsoft Activ ...
- Sql Server使用正则表达式
近日因项目需求,需要在sql server中用到正则表达式,因Sql Server本身并不支持正则表达式,需要用到Clr函数. 在此记录一下步骤,与大家共享,虽然写的是原创,但有参考网上的文章. 1. ...
随机推荐
- 没想到: System.out.println(n1 == f1 ? n1 : f1);
int n1 = 404; float f1 = 404.0f; if(n1 == f1) { System.out.println("两者相等"); } System.out.p ...
- Jenkins安装后无法安装插件
处理方法 Jenkins -- 管理插件 -- 高级 -- 升级站点 将URL 中的https 改为 http
- (N叉树 DFS 递归 BFS) leetcode 559. Maximum Depth of N-ary Tree
Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...
- FFT & FNT 简要整理
几周前搞了搞--有点时间简要整理一下,诸多不足之处还请指出. 有哪些需要理解的地方? 点值表示:对于多项式 \(A(x)\),把 \(n\) 个不同的 \(x\) 代入,会得出 \(n\) 个不同的 ...
- UI命名规范
Ui控件汇总 按钮 单行文本框 多行文本框 水平滑动条 垂直滑动条 水平滚动条 垂直滚动条 进度条 下拉列表框 复选框 UI命名规范 UI文字做好备份,方便后期维护修改 按钮命名规范:btn_ 第一个 ...
- django --视图装饰器
- 用CSS实现加载的动画效果
用纯CSS实现加载的一些动态效果,可以把加载效果中的元素分成很多个小部分,每个部分都有动画,每个部分的动画再设置相应的延迟效果,这样,看起来就是连贯的加载动画效果.代码如下: 1.效果1 <di ...
- 2018-2019-2 20165234 《网络对抗技术》 Exp4 恶意代码分析
实验四 恶意代码分析 实验目的 1.监控自己系统的运行状态,看有没有可疑的程序在运行. 2.分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals ...
- 命令行神器之argparse使用笔记
示例 废话不多说直接给例子: import argparse parser = argparse.ArgumentParser(description='Imbalanced Dataset Exam ...
- Linux代理搭建TinyProxy
操作系统:阿里云CentOS 7.4 64位 安装方法: yum install tinyproxy 配置: vi /etc/tinyproxy/tinyproxy.conf Port 8888 // ...