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—函数进阶篇

    lambda表达式(匿名函数表达式) 作用:创建一个匿名函数对象.同def类似,但不提供函数名. 语法:lambda [形参1,形参2,...] : 表达式 语法说明 lambda 只是一个表达式,它 ...

  2. Jmeter之命令行生成HTML报告

    其实每次使用jemter.bat文件启动JMeter时,命令行窗口都会提示我们不要使用GUI窗口进行测试,除非是进行调试脚本 使用命令行生成结果也很测试报告也很简单 jmeter -n -t [jmx ...

  3. axios如何先请求A接口然后在请求B接口

    总结:在第一个then的请求结束后,在添加一个then,表示请求第二个接口,在第二个then里面写第二个接口的请求方式 axios.get("./a.json").then(res ...

  4. tarjan 缩点 + 几道例题

    tarjan 缩点 + 几道例题 tarjan 模板 #include <iostream> #include <string.h> using namespace std; ...

  5. office 小技巧

    1. 数据匹配 VLOOKUP 例一:如图,将左表(sheet1)的e列关联到右表(sheet2),条件为: sheet2.字段名 = sheet1.D 公式:=VLOOKUP(sheet2!D2:D ...

  6. Python进阶-XVV hashlib模块、configparse模块、logging模块

    1.配置相关的configparse模块 配置文件如何组织?python中常见的是将配置文件写成py,然后引入该模块即可.优点是方便访问. 但是也有用类似windows中的ini文件的配置文件,了解即 ...

  7. vs code 中配置git go

    { "window.zoomLevel": 1, "editor.fontSize": 15, //"files.autoSave": &q ...

  8. json去除value值的前后空格

    /** * @Title: JsonStrTrim * @author : jsw * @date : 2012-12-7 * @time : 上午09:19:18 * @Description: 传 ...

  9. IPv6 邻居状态迁移

  10. Python连载34-信息队列

    一.生产者消费者模型 1.一个模型.可以用来搭建消息队列:queue是一个用来存放变量的数据结构,特点是:先进先出 import threading import time import queue ...