SQL Server 使用union all查询多个条件数据合并分组显示,同比统计
select CONVERT(char(7),a.created_yearmonth,20) created_yearmonth,
a.countaccount countaccount,
a.yxsl yxsl,
a.sccdsl sccdsl,
a.zccdsl zccdsl
from
(--总数
select CONVERT(char(7),account.created,20) created_yearmonth,
count(1) countaccount,
null yxsl,
null sccdsl,
null zccdsl
from account account
left join org_dep iddep
on iddep.id=account.iddep
left join org_employee idowner
on idowner.id=account.idowner
group by CONVERT(char(7),account.created,20)
union all
--有效
select CONVERT(char(7),account.created,20) created_yearmonth,
null countaccount,
count(1) yxsl,
null sccdsl,
null zccdsl
from account account
left join org_dep iddep
on iddep.id=account.iddep
left join org_employee idowner
on idowner.id=account.idowner
where account.emshzt in( 'bad4d977a06604e2ec5621bd0285eef2')
group by CONVERT(char(7),account.created,20)
union all
--首次成交
select CONVERT(char(7),account.created,20) created_yearmonth,
null countaccount,
null yxsl,
count(1) sccdsl,
null zccdsl
from account account
left join org_dep iddep
on iddep.id=account.iddep
left join org_employee idowner
on idowner.id=account.idowner
where account.dbcdcs = 1
group by CONVERT(char(7),account.created,20)
union all
--再次成交
select CONVERT(char(7),account.created,20) created_yearmonth,
null countaccount,
null yxsl,
null sccdsl,
count(1) zccdsl
from account account
left join org_dep iddep
on iddep.id=account.iddep
left join org_employee idowner
on idowner.id=account.idowner
where account.dbcdcs > 1
group by CONVERT(char(7),account.created,20)
) a
SQL Server 使用union all查询多个条件数据合并分组显示,同比统计的更多相关文章
- Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 2 -使用XQuery 查询XML数据
XQuery 是一个浏览/返回XML实例的标准语言. 它比老的只能简单处理节点的XPath表达式更丰富. 你可以同XPath一样使用.或是遍历所有节点,塑造XML实例的返回等. 作为一个查询语言, 你 ...
- Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集
XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...
- 第1/24周 SQL Server 如何执行一个查询
大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Server如何执行一个查询来建立基础.这个部分非常重要, ...
- 在SQL Server 2016里使用查询存储进行性能调优
作为一个DBA,排除SQL Server问题是我们的职责之一,每个月都有很多人给我们带来各种不能解释却要解决的性能问题. 我就多次听到,以前的SQL Server的性能问题都还好且在正常范围内,但现在 ...
- Sql Server来龙去脉系列之三 查询过程跟踪
我们在读写数据库文件时,当文件被读.写或者出现错误时,这些过程活动都会触发一些运行时事件.从一个用户角度来看,有些时候会关注这些事件,特别是我们调试.审核.服务维护.例如,当数据库错误出现.列数据被更 ...
- SQL Server 锁表、查询被锁表、解锁相关语句
SQL Server 锁表.查询被锁表.解锁相关语句,供参考. --锁表(其它事务不能读.更新.删除) BEGIN TRAN SELECT * FROM <表名> WITH(TABLOCK ...
- Sql Server数据库设计高级查询
-------------------------------------第一章 数据库的设计------------------------------------- 软件开发周期: (1 ...
- SQL Server,Access数据库查询易混点和C#中parameter指定参数长度的优缺点
在学校的时候就经常做一些网站,所以这次在公司实习,组长第一次给了一个企业的网站还是很快的完成了.中间并没有遇到什么大的问题,但是还是遇到了两个新手非常容易混淆的小问题,所以拿出来跟大家分享一下. 主要 ...
- 第1周 SQL Server 如何执行一个查询
原文:第1周 SQL Server 如何执行一个查询 大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Se ...
随机推荐
- Python函数作用域和匿名函数
匿名函数的定义 全局变量和局部变量的概念 global(全局变量)和 nonlocal(局部变量) 闭包.递归.回调 匿名函数 匿名函数 lambda 语法规则:lambda 参数 : 表达式 ...
- [android]system.img文件的打包和解包
1:system.img的两种格式 system2_0.img: Linux rev 1.0 ext4 filesystem data, UUID=57f8f4bc-abf4-655f-bf67-94 ...
- 【cf1111】C. Creative Snap (dfs+dp)
传送门 简单的dfs+dp即可解决.根本不用动态开点 /* * Author: heyuhhh * Created Time: 2019/11/13 10:12:42 */ #include < ...
- IEEE754 浮点数
IEEE754 浮点数 1.阅读IEEE754浮点数 A,阶码是用移码表示的,这里会有一个127的偏移量,它的127相当于0,小于127时为负,大于127时为正,比如:10000001表示指数为129 ...
- 7、zabbix自定义监控阈值-前端页面报警
找个值监控一下: #监控passwd #默认是间隔是1小时,我们改成10秒,下面我们要把报警打开 #我们在被监控上的主机上创建一个新用户,过10秒,界面上就会报警了 ----------------- ...
- MongoDB介绍(一)
MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功 ...
- webapi使用ExceptionFilterAttribute过滤器
文章 public class ApiExceptionFilterAttribute:ExceptionFilterAttribute { public override void OnExcept ...
- 洛谷P1283 平板涂色 &&一本通1445:平板涂色
题目描述 CE数码公司开发了一种名为自动涂色机(APM)的产品.它能用预定的颜色给一块由不同尺寸且互不覆盖的矩形构成的平板涂色. 为了涂色,APM需要使用一组刷子.每个刷子涂一种不同的颜色C.APM拿 ...
- Web前端开发框架大全-详述
可以说,前端技术的发展是互联网自身发展的一个缩影! 前端技术的发展经历了web1.0时代,即网页只能展示信息,几乎没有交互可言: web2.0时代,web2.0不再是单维的,逐渐发展为双向交流,另一特 ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary 水题
C. p-binary Vasya will fancy any number as long as it is an integer power of two. Petya, on the othe ...