With语句在数据统计应用
WITH TMP_EXECUTOR(EXECUTOR,EXECUTORNAME) AS
( SELECT DISTINCT T.EXECUTOR ,T1.FULLNAME AS EXECUTORNAME
FROM (SELECT DISTINCT T1.TASKID
, T2.EXECUTOR
FROM RT_CALLTASKDEF T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.TASKID = T2.TASKID
WHERE T1.TASKTYPE = '' AND DATE (T1.EXPECTSTARTDATE) <= '2015-02-09') T
LEFT JOIN CM_STAFF T1 ON T1.STAFFPKID = T.EXECUTOR
WHERE T.EXECUTOR IS NOT NULL ) SELECT DISTINCT EXECUTOR, EXECUTORNAME,
MAX(TASKCOUNT) OVER(PARTITION BY EXECUTOR) AS TASKCOUNT,
MAX(PRESOLICITCOUNT) OVER(PARTITION BY EXECUTOR) AS PRESOLICITCOUNT,
MAX(SOLICITINGCOUNT) OVER(PARTITION BY EXECUTOR) AS SOLICITINGCOUNT,
MAX(ACTIVEBOOKCOUNT) OVER(PARTITION BY EXECUTOR) AS ACTIVEBOOKCOUNT,
MAX(ACTIVEBOOKTOSHOPCOUNT) OVER(PARTITION BY EXECUTOR) AS ACTIVEBOOKTOSHOPCOUNT,
MAX(ACTIVEBOOKINSHOPCOUNT) OVER(PARTITION BY EXECUTOR) AS ACTIVEBOOKINSHOPCOUNT,
MAX(PASSIVEBOOKCOUNT) OVER(PARTITION BY EXECUTOR) AS PASSIVEBOOKCOUNT,
MAX(BACKEDFACTORYCOUNT) OVER(PARTITION BY EXECUTOR) AS BACKEDFACTORYCOUNT,
MAX(DEFEATCOUNT) OVER(PARTITION BY EXECUTOR) AS DEFEATCOUNT,
MAX(CALLSUCCESSCOUNT) OVER(PARTITION BY EXECUTOR) AS CALLSUCCESSCOUNT,
MAX(CALLTIMELENGTH) OVER(PARTITION BY EXECUTOR) AS CALLTIMELENGTH FROM ( SELECT T1.EXECUTOR,T1.EXECUTORNAME,COUNT(T2.TASKID) AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.EXECUTOR = T2.EXECUTOR WHERE (T2.TASKSTATUS = '' OR T2.TASKSTATUS = '') GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, COUNT(T2.TASKID) AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.EXECUTOR = T2.EXECUTOR WHERE (T2.TASKSTATUS = '') GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, COUNT(T2.TASKID) AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.EXECUTOR = T2.EXECUTOR WHERE (T2.TASKSTATUS = '') GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, COUNT(T2.BOOKINGNO) AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,T2.BOOKINGNO FROM RT_CALLTASKREC T1
LEFT JOIN RT_CALLTASKRECDT T2 ON T1.TASKID = T2.TASKID
LEFT JOIN RT_BOOKING T3 ON T2.BOOKINGNO = T3.BOOKINGNO WHERE T2.BOOKINGNO IS NOT NULL
) T2 ON T1.EXECUTOR = T2.EXECUTOR GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, COUNT(T2.BOOKINGNO) AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,T2.BOOKINGNO FROM RT_CALLTASKREC T1
LEFT JOIN RT_CALLTASKRECDT T2 ON T1.TASKID = T2.TASKID
LEFT JOIN RT_BOOKING T3 ON T2.BOOKINGNO = T3.BOOKINGNO WHERE T2.BOOKINGNO IS NOT NULL
) T2 ON T1.EXECUTOR = T2.EXECUTOR GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, COUNT(T2.BOOKINGNO) AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,T2.BOOKINGNO FROM RT_CALLTASKREC T1
LEFT JOIN RT_CALLTASKRECDT T2 ON T1.TASKID = T2.TASKID
LEFT JOIN RT_BOOKING T3 ON T2.BOOKINGNO = T3.BOOKINGNO WHERE T2.BOOKINGNO IS NOT NULL
) T2 ON T1.EXECUTOR = T2.EXECUTOR GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, COUNT(T2.BOOKINGNO) AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,T2.BOOKINGNO FROM TMP_EXECUTOR T1
LEFT JOIN RT_BOOKING T2 ON T1.EXECUTOR = T2.OPERTATOR WHERE T2.BOOKINGNO IS NOT NULL
) T2 ON T1.EXECUTOR = T2.EXECUTOR GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, COUNT(T2.TASKID) AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.EXECUTOR = T2.EXECUTOR WHERE (T2.TASKSTATUS = '') GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, COUNT(T2.TASKID) AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN RT_CALLTASKREC T2 ON T1.EXECUTOR = T2.EXECUTOR WHERE (T2.TASKSTATUS = '') GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, COUNT(T2.TALKNOTESID) AS CALLSUCCESSCOUNT, 0 AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,T4.TALKNOTESID FROM RT_CALLTASKREC T1
LEFT JOIN RT_CALLTASKRECDT T2 ON T1.TASKID = T2.TASKID
LEFT JOIN RT_CALLTASKVOICE T3 ON T2.TASKID = T3.TASKID AND T2.LINENO = T3.LINENO
LEFT JOIN RS_TALKNOTES T4 ON T3.VOICEID = T4.TALKNOTESID
WHERE VALUE(T4.ISCALLIN,'Y') <> 'Y' AND T4.TALKLENGTH > 30000
) T2 ON T1.EXECUTOR = T2.EXECUTOR GROUP BY T1.EXECUTOR, T1.EXECUTORNAME UNION ALL SELECT T1.EXECUTOR,T1.EXECUTORNAME,0 AS TASKCOUNT, 0 AS PRESOLICITCOUNT, 0 AS SOLICITINGCOUNT
, 0 AS ACTIVEBOOKCOUNT, 0 AS ACTIVEBOOKTOSHOPCOUNT, 0 AS ACTIVEBOOKINSHOPCOUNT, 0 AS PASSIVEBOOKCOUNT, 0 AS BACKEDFACTORYCOUNT
, 0 AS DEFEATCOUNT, 0 AS CALLSUCCESSCOUNT, VALUE(T2.CALLTIMELENGTH ,0) AS CALLTIMELENGTH
FROM TMP_EXECUTOR T1
LEFT JOIN
(
SELECT DISTINCT T1.EXECUTOR,SUM(T4.TALKLENGTH) AS CALLTIMELENGTH FROM RT_CALLTASKREC T1
LEFT JOIN RT_CALLTASKRECDT T2 ON T1.TASKID = T2.TASKID
LEFT JOIN RT_CALLTASKVOICE T3 ON T2.TASKID = T3.TASKID AND T2.LINENO = T3.LINENO
LEFT JOIN RS_TALKNOTES T4 ON T3.VOICEID = T4.TALKNOTESID
WHERE VALUE(T4.ISCALLIN,'Y') <> 'Y' AND T4.TALKLENGTH > 30000 GROUP BY T1.EXECUTOR
) T2 ON T1.EXECUTOR = T2.EXECUTOR ) X
With语句在数据统计应用的更多相关文章
- 大数据学习day33----spark13-----1.两种方式管理偏移量并将偏移量写入redis 2. MySQL事务的测试 3.利用MySQL事务实现数据统计的ExactlyOnce(sql语句中出现相同key时如何进行累加(此处时出现相同的单词))4 将数据写入kafka
1.两种方式管理偏移量并将偏移量写入redis (1)第一种:rdd的形式 一般是使用这种直连的方式,但其缺点是没法调用一些更加高级的api,如窗口操作.如果想更加精确的控制偏移量,就使用这种方式 代 ...
- 常用的数据统计Sql 总结
最近刚在搞一个BI的项目,里面需要大量的sql 数据统计相关运用,加深了我又对SQL的理解与使用. 所以,分享几个数据统计时常用的sql 语句总结: 1. 统计各个条件下的数据 select Batc ...
- SQL Server读懂语句运行的统计信息 SET STATISTICS TIME IO PROFILE ON
对于语句的运行,除了执行计划本身,还有一些其他因素要考虑,例如语句的编译时间.执行时间.做了多少次磁盘读等. 如果DBA能够把问题语句单独测试运行,可以在运行前打开下面这三个开关,收集语句运行的统计信 ...
- 常用的数据统计Sql 总结(转)
转:http://www.cnblogs.com/zhangweizhong/p/5577842.html 最近刚在搞一个BI的项目,里面需要大量的sql 数据统计相关运用,加深了我又对SQL的理解与 ...
- SQLSERVER读懂语句运行的统计信息
SQLSERVER读懂语句运行的统计信息 对于语句的运行,除了执行计划本身,还有一些其他因素要考虑,例如语句的编译时间.执行时间.做了多少次磁盘读等. 如果DBA能够把问题语句单独测试运行,可以在运行 ...
- [C++]竞赛模板·数据统计与IO(重定向版与非重定向版)
/* 数据统计与IO 重定向版模板 描述:本机测试用文件数据流重定向,一旦提交到比赛就自动“删除”重定向语句 */ # define LOCAL #include<stdio.h> # ...
- redis 数据统计(用自增id防止同一秒并发过大没统计成功)
Redis 缓存保存某段时间累加的数值,加入最大id防止同一秒并发过大,导致只统计了执行时同一秒的部分数据,而同一秒另一部分数据在下次累加时没有统计到缓存中 //coin总数 public funct ...
- 有关“数据统计”的一些概念 -- PV UV VV IP跳出率等
有关"数据统计"的一些概念 -- PV UV VV IP跳出率等 版权声明:本文为博主原创文章,未经博主允许不得转载. 此文是本人工作中碰到的,随时记下来的零散概念,特此整理一下. ...
- TFS工作项数据统计及相关数据库结构分析
今天为客户的质量管理部门人员提供TFS咨询过程中,客户的质量管理专家基于TFS提出了一个比较棘手的数据统计需求.需求是这样,客户的数十个软件项目通过质量管理部按照年度版本计划进行软件产品系统的发布,因 ...
随机推荐
- HDU 5657 CA Loves Math 状压DP + 枚举
题意: 给出\(A(2 \leq A \leq 11), n(0 \leq n \leq 10^9), k(1 \leq k \leq 10^9)\). 求区间\([1, A^n]\)中各个数字互不相 ...
- 【Restore IP Addresses 】cpp
题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...
- 【Median of Two Sorted Arrays】cpp
题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sor ...
- Linux之如何进行固定IP、DNS等设置
前提:虚拟机Linux centOS6.6 Linux如何设置固定IP.dns.网关 1.切换到root账号 2.#cd /etc/sysconfig/network-scripts 进入网卡的设置 ...
- [python][django学习篇][6]操作数据库
查询(取)数据 >>> Category.objects.all() <QuerySet [<Category: Category object>]> > ...
- [错误解决]paramiko.ssh_exception.SSHException: Error reading SSH protocol banner 设置
报错信息 上午的时候数据组的同事跟我说有几个程序报错,经过查看log发现找到报错信息: paramiko.ssh_exception.SSHException: Error reading SSH p ...
- Spring整合hibernate -声明事务管理
目录 1 sessionFactory 注入HibernateTransactionManager 2 XML配置的配置 3 添加annotation-driven 4 引入JAR包 5在servi ...
- java的ArrayList使用方法详解
ArrayList是Java的链表类,在项目开发中十分常见,那么怎样对ArrayList进行添加.删除.修改.查询.遍历呢?本文将进行详细阐述. 工具/原料 java 一.ArrayList的添加 ...
- hdu6134[莫比乌斯反演] 2017多校8
/*hdu6134[莫比乌斯反演] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long long LL ...
- Rust学习资源和路线
Rust学习资源和路线 来源 https://rust-lang-cn.org/article/23 学习资源 The Rust Programming Language 堪称Rust的"T ...