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查询多个条件数据合并分组显示,同比统计的更多相关文章

  1. Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 2 -使用XQuery 查询XML数据

    XQuery 是一个浏览/返回XML实例的标准语言. 它比老的只能简单处理节点的XPath表达式更丰富. 你可以同XPath一样使用.或是遍历所有节点,塑造XML实例的返回等. 作为一个查询语言, 你 ...

  2. Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集

    XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...

  3. 第1/24周 SQL Server 如何执行一个查询

    大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Server如何执行一个查询来建立基础.这个部分非常重要, ...

  4. 在SQL Server 2016里使用查询存储进行性能调优

    作为一个DBA,排除SQL Server问题是我们的职责之一,每个月都有很多人给我们带来各种不能解释却要解决的性能问题. 我就多次听到,以前的SQL Server的性能问题都还好且在正常范围内,但现在 ...

  5. Sql Server来龙去脉系列之三 查询过程跟踪

    我们在读写数据库文件时,当文件被读.写或者出现错误时,这些过程活动都会触发一些运行时事件.从一个用户角度来看,有些时候会关注这些事件,特别是我们调试.审核.服务维护.例如,当数据库错误出现.列数据被更 ...

  6. SQL Server 锁表、查询被锁表、解锁相关语句

    SQL Server 锁表.查询被锁表.解锁相关语句,供参考. --锁表(其它事务不能读.更新.删除) BEGIN TRAN SELECT * FROM <表名> WITH(TABLOCK ...

  7. Sql Server数据库设计高级查询

    -------------------------------------第一章  数据库的设计------------------------------------- 软件开发周期:     (1 ...

  8. SQL Server,Access数据库查询易混点和C#中parameter指定参数长度的优缺点

    在学校的时候就经常做一些网站,所以这次在公司实习,组长第一次给了一个企业的网站还是很快的完成了.中间并没有遇到什么大的问题,但是还是遇到了两个新手非常容易混淆的小问题,所以拿出来跟大家分享一下. 主要 ...

  9. 第1周 SQL Server 如何执行一个查询

    原文:第1周 SQL Server 如何执行一个查询 大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Se ...

随机推荐

  1. Python—函数基础篇

    https://www.cnblogs.com/littlefivebolg/p/9017449.html Python 解释器的内置函数 内置函数 作用 实例 abs() 返回数字的绝对值. abs ...

  2. fiddler---Fiddler接口测试

    前面介绍了Fiddler一些简单的使用功能,Fiddler不仅可以抓包也可以做接口工具使用,在没有接口文档的时候我们也可以通过Fiddler查看接口具体有哪些内容 Fiddler发送请求 在Fiddl ...

  3. C++:基本类型的转换

    C++:基本类型的转换 一.string转为int [参考:https://blog.csdn.net/m0_37316917/article/details/82712017] string num ...

  4. 5.Python网络编程_通过继承实现多线程

    import threading import time #继承形式的多线程,适合于程序比较复杂的情况 class MyThread(threading.Thread): #t.start()会调用r ...

  5. openpyxl的简单使用

    openpyxl的简单使用 openpyxl 操作excel的库,只能操作xlxs 文件, xlrd/xlwt这两个库能兼容xls(2003版) 安装 pip install openpyxl如果ex ...

  6. pushgateway

    下载pushgateway wget https://github.com/prometheus/pushgateway/releases/download/v0.9.0/pushgateway-0. ...

  7. skkyk:题解 洛谷P2420 【让我们异或吧】lca+xor前缀和

    刚学了LCA,写篇题解巩固一下 首先题目有误: (A是否是男生 )xor( B是否是男生)=A和B是否能够成为情侣,这句话显然是错误的qwq 对于这道题,容易看出,对于待处理的两个点,只要我们找到他的 ...

  8. 牛客OI周赛13-提高组-0还是1-(dp+位运算)

    https://ac.nowcoder.com/acm/contest/2970/A 给出长度为n的一连串位运算符号,用n+1个0或1使运算插入最后得到1,求01序列有多少种可能. dp[i][j]表 ...

  9. 杂记(C语言中的不知怎么归类的细小点。)

    1.int a; printf("%d",2a); 从数学上讲,没有丝毫问题,但是在计算机上,就无法识别!        纠正:应写成2*a. 2.关于输出结果保留一位小数的:不应 ...

  10. matplotlib动态绘图

    目录 package Process 解决中文乱码问题 simple_plot() scatter_plot() three_dimension_scatter() Jupyter notebook ...