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. [日常] gocron源码阅读-go语言的变量

    变量的声明形式是这样的 var 变量名字 类型 = 表达式var ( AppVersion = "1.5" BuildDate, GitCommit string)类型可以被省略, ...

  2. STM32HAL快速上手

    STM32HAL快速上手 资料下载 如果在下面的网站中没有账户,建议用edu邮箱创建账户. STMicroeletronic 意法半导体官网 首页 - STMicroelectronics 意法半导体 ...

  3. 线上可用django和gunicorn的dockerfile内容

    一,基础镜像 [xxx.com.cn/3rd_part/python.3.6.8:alpine3.9-mysqlclient1.4.2] FROM python:3.6.8-alpine3.7 MAI ...

  4. PHP注释标记整理

    什么是注释标记 我们在平常写代码或看别人写的代码时, 在方法的说明注释中经常会有这样的注释: /** * @param $num * @return array */ 上面的@param @retur ...

  5. HTML与CSS学习笔记(7)

    1.响应式布局 利用媒体查询,即media queries,可以针对不同的媒体类型定义不同的样式,从而实现响应式布局. 常见选项: 媒体类型 and.not min-width.max-width: ...

  6. Conda和Python的国内安装源

    Conda和Python的国内安装源 Windows系统: 更换python国内源的方法. 在"C:\Users[xxxx]\pip\pip.ini"文件中配置如下内容(没有则新建 ...

  7. (day54)六、事务、分组、F、Q、常用字段、事务

    目录 一.聚合查询aggregate 二.分组查询annotate 三.F与Q查询 (一)F查询 1. 查询库存数大于卖出数的书籍 2. 将所有书的价格上涨100块 3.将所有书的名称后面全部加上 & ...

  8. pandas-缺失值处理

    import pandas as pd import numpy as np Step 1.加载数据集 # header=0以第一行作为列名 tip = pd.read_csv("lianx ...

  9. spring cloud启动zipkin,报错maven依赖jar包冲突 Class path contains multiple SLF4J bindings

    项目启动报错: Connected to the target VM, address: '127.0.0.1:59412', transport: 'socket' SLF4J: Class pat ...

  10. 深入理解Java8中Stream的实现原理

    Stream Pipelines 前面我们已经学会如何使用Stream API,用起来真的很爽,但简洁的方法下面似乎隐藏着无尽的秘密,如此强大的API是如何实现的呢?比如Pipeline是怎么执行的, ...