1、上面是目标表,其中激活客户数为当月每天之前30天未下单的客户

2、写SQL

SELECT a.销售员,c.当月销售确认额,a.当月订单额,b.当月首单数,b.当月激活数,
a1,b.b1,b.c1,a2,b.b2,b.c2,a3,b.b3,b.c3,a4,b.b4,b.c4,a5,b.b5,b.c5,a6,b.b6,b.c6,a7,b.b7,b.c7,a8,b.b8,b.c8,a9,b.b9,b.c9,a10,b.b10,b.c10,a11,b.b11,b.c11,a12,b.b12,b.c12,a13,b.b13,b.c13,a14,b.b14,b.c14,a15,b.b15,b.c15,
a16,b.b16,b.c16,a17,b.b17,b.c17,a18,b.b18,b.c18,a19,b.b19,b.c19,a20,b.b20,b.c20,a21,b.b21,b.c21,a22,b.b22,b.c22,a23,b.b23,b.c23,a24,b.b24,b.c24,a25,b.b25,b.c25,a26,b.b26,b.c26,a27,b.b27,b.c27,a28,b.b28,b.c28,
a29,b.b29,b.c29,a30,b.b30,b.c30,a31,b.b31,b.c31
FROM (
SELECT a1.销售员,SUM(a1.金额) AS 当月订单额,#当月订单额及每天订单额
SUM(IF(DAY(a1.订单日期)=1,金额,NULL)) AS a1,SUM(IF(DAY(a1.订单日期)=2,金额,NULL)) AS a2,SUM(IF(DAY(a1.订单日期)=3,金额,NULL)) AS a3,
SUM(IF(DAY(a1.订单日期)=4,金额,NULL)) AS a4,SUM(IF(DAY(a1.订单日期)=5,金额,NULL)) AS a5,SUM(IF(DAY(a1.订单日期)=6,金额,NULL)) AS a6,
SUM(IF(DAY(a1.订单日期)=7,金额,NULL)) AS a7,SUM(IF(DAY(a1.订单日期)=8,金额,NULL)) AS a8,SUM(IF(DAY(a1.订单日期)=9,金额,NULL)) AS a9,
SUM(IF(DAY(a1.订单日期)=10,金额,NULL)) AS a10,SUM(IF(DAY(a1.订单日期)=11,金额,NULL)) AS a11,SUM(IF(DAY(a1.订单日期)=12,金额,NULL)) AS a12,
SUM(IF(DAY(a1.订单日期)=13,金额,NULL)) AS a13,SUM(IF(DAY(a1.订单日期)=14,金额,NULL)) AS a14,SUM(IF(DAY(a1.订单日期)=15,金额,NULL)) AS a15,
SUM(IF(DAY(a1.订单日期)=16,金额,NULL)) AS a16,SUM(IF(DAY(a1.订单日期)=17,金额,NULL)) AS a17,SUM(IF(DAY(a1.订单日期)=18,金额,NULL)) AS a18,
SUM(IF(DAY(a1.订单日期)=19,金额,NULL)) AS a19,SUM(IF(DAY(a1.订单日期)=20,金额,NULL)) AS a20,SUM(IF(DAY(a1.订单日期)=21,金额,NULL)) AS a21,
SUM(IF(DAY(a1.订单日期)=22,金额,NULL)) AS a22,SUM(IF(DAY(a1.订单日期)=23,金额,NULL)) AS a23,SUM(IF(DAY(a1.订单日期)=24,金额,NULL)) AS a24,
SUM(IF(DAY(a1.订单日期)=25,金额,NULL)) AS a25,SUM(IF(DAY(a1.订单日期)=26,金额,NULL)) AS a26,SUM(IF(DAY(a1.订单日期)=27,金额,NULL)) AS a27,
SUM(IF(DAY(a1.订单日期)=28,金额,NULL)) AS a28,SUM(IF(DAY(a1.订单日期)=29,金额,NULL)) AS a29,SUM(IF(DAY(a1.订单日期)=30,金额,NULL)) AS a30,
SUM(IF(DAY(a1.订单日期)=31,金额,NULL)) AS a31
FROM `a003_order` AS a1
WHERE a1.销售员 IS NOT NULL AND a1.城市="北京" AND DATE_FORMAT(a1.订单日期,"%Y%m")=DATE_FORMAT(DATE_ADD(CURRENT_DATE,INTERVAL - 1 DAY),"%Y%m") AND a1.订单日期<CURRENT_DATE
GROUP BY a1.销售员
) AS a
LEFT JOIN (
SELECT b5.销售员,SUM(IF(b5.激活情况="新增",1,NULL))AS 当月首单数,SUM(IF(b5.激活情况="重激活",1,NULL)) AS 当月激活数,#首单数
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=1,1,NULL)) AS b1,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=2,1,NULL)) AS b2,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=3,1,NULL)) AS b3,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=4,1,NULL)) AS b4,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=5,1,NULL)) AS b5,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=6,1,NULL)) AS b6,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=7,1,NULL)) AS b7,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=8,1,NULL)) AS b8,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=9,1,NULL)) AS b9,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=10,1,NULL)) AS b10,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=11,1,NULL)) AS b11,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=12,1,NULL)) AS b12,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=13,1,NULL)) AS b13,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=14,1,NULL)) AS b14,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=15,1,NULL)) AS b15,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=16,1,NULL)) AS b16,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=17,1,NULL)) AS b17,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=18,1,NULL)) AS b18,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=19,1,NULL)) AS b19,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=20,1,NULL)) AS b20,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=21,1,NULL)) AS b21,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=22,1,NULL)) AS b22,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=23,1,NULL)) AS b23,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=24,1,NULL)) AS b24,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=25,1,NULL)) AS b25,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=26,1,NULL)) AS b26,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=27,1,NULL)) AS b27,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=28,1,NULL)) AS b28,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=29,1,NULL)) AS b29,SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=30,1,NULL)) AS b30,
SUM(IF(b5.激活情况="新增" AND DAY(b5.当月首单日期)=31,1,NULL)) AS b31,
#SUM(IF(b5.激活情况="重激活",1,NULL)) AS 当月激活数,#激活数
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=1,1,NULL)) AS c1,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=2,1,NULL)) AS c2,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=3,1,NULL)) AS c3,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=4,1,NULL)) AS c4,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=5,1,NULL)) AS c5,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=6,1,NULL)) AS c6,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=7,1,NULL)) AS c7,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=8,1,NULL)) AS c8,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=9,1,NULL)) AS c9,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=10,1,NULL)) AS c10,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=11,1,NULL)) AS c11,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=12,1,NULL)) AS c12,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=13,1,NULL)) AS c13,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=14,1,NULL)) AS c14,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=15,1,NULL)) AS c15,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=16,1,NULL)) AS c16,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=17,1,NULL)) AS c17,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=18,1,NULL)) AS c18,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=19,1,NULL)) AS c19,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=20,1,NULL)) AS c20,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=21,1,NULL)) AS c21,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=22,1,NULL)) AS c22,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=23,1,NULL)) AS c23,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=24,1,NULL)) AS c24,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=25,1,NULL)) AS c25,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=26,1,NULL)) AS c26,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=27,1,NULL)) AS c27,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=28,1,NULL)) AS c28,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=29,1,NULL)) AS c29,SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=30,1,NULL)) AS c30,
SUM(IF(b5.激活情况="重激活" AND DAY(b5.当月首单日期)=31,1,NULL)) AS c31
FROM (
SELECT b3.用户ID,b3.销售员,b3.订单日期 AS 当月首单日期,
SUM(IF(DATE(b4.订单日期)<b3.订单日期 AND b4.金额>0,b4.金额,NULL)) AS 当月首单日以前总金额,
SUM(IF(DATE(b4.订单日期)<=DATE_ADD(b3.订单日期,INTERVAL -30 DAY) AND b4.金额>0,b4.金额,NULL)) AS 当月首单日前30天之前金额,
SUM(IF(DATE(b4.订单日期)>DATE_ADD(b3.订单日期,INTERVAL -30 DAY) AND DATE(b4.订单日期)<b3.订单日期 AND b4.金额>0,b4.金额,NULL)) AS 当月首单日前30天金额,
b3.订单额 AS 当月首单日金额,
CASE
WHEN SUM(IF(DATE(b4.订单日期)<b3.订单日期 AND b4.金额>0,b4.金额,NULL)) IS NULL THEN "新增"
WHEN SUM(IF(DATE(b4.订单日期)>DATE_ADD(b3.订单日期,INTERVAL -30 DAY) AND DATE(b4.订单日期)<b3.订单日期 AND b4.金额>0,金额,NULL)) IS NOT NULL THEN "留存"
WHEN SUM(IF(DATE(b4.订单日期)<=DATE_ADD(b3.订单日期,INTERVAL -30 DAY) AND b4.金额>0,金额,NULL)) IS NOT NULL AND SUM(IF(DATE(b4.订单日期)>DATE_ADD(b3.订单日期,INTERVAL -30 DAY) AND DATE(b4.订单日期)<b3.订单日期 AND b4.金额>0,金额 ,NULL)) IS NULL THEN "重激活"
ELSE NULL END AS 激活情况
FROM (
SELECT b2.用户ID,b2.订单日期,b2.销售员 AS 销售员,b2.订单额#取出当月首单订单日期 首单销售 首单额 以这个日期往前推30天判断激活留存情况
FROM (
SELECT b1.用户ID,DATE(b1.订单日期) AS 订单日期,b1.销售员,SUM(金额) AS 订单额 #当月下单用户每天明细
FROM `a003_order` AS b1
WHERE b1.城市="北京" AND DATE_FORMAT(b1.订单日期,"%Y%m")=DATE_FORMAT(DATE_ADD(CURRENT_DATE,INTERVAL - 1 DAY),"%Y%m") AND b1.订单日期<CURRENT_DATE AND b1.金额>0
GROUP BY b1.用户ID,DATE(b1.订单日期)
) AS b2
GROUP BY b2.用户ID
) AS b3
LEFT JOIN `a003_order` AS b4 ON b4.用户ID=b3.用户ID
#where b3.用户ID=22200
GROUP BY b3.用户ID
) AS b5
WHERE b5.销售员 IS NOT NULL
GROUP BY b5.销售员
) AS b ON a.销售员=b.销售员
LEFT JOIN (#05表销售确认额
SELECT c1.销售员,SUM(c1.销售额) AS 当月销售确认额
FROM `a005_account` AS c1
WHERE c1.销售员 IS NOT NULL AND c1.城市="北京" AND DATE_FORMAT(c1.应收日,"%Y%m")=DATE_FORMAT(DATE_ADD(CURRENT_DATE,INTERVAL - 1 DAY),"%Y%m") AND c1.应收日<CURRENT_DATE
GROUP BY c1.销售员
) AS c ON a.销售员=c.销售员
ORDER BY a.当月订单额 DESC

3、做excel模板

将上面SQL数据导入excel中 设置好格式表头 删除数据  还是用到SUMif函数 把所有销售员当月每天的这两个指标都用公式计算出来

4、保存excel模板 文件名设置成英文名  * _style.xlsx 这样结尾最好

5、设置kettle转换

设置好数据库连接服务器 表输入里选择数据库连接 表输出选择excel表输出 调用第4步excel模板文件* _style.xlsx

6、执行转换检测生成的数据和预设的格式是否相同 如果相同进行第7步即可 不相同再调整excel模板

7、设置发邮件作业 收件人地址 发件人地址 用户名 密码 服务器端口等设置好

kettle监控销售人员当月每天任务完成率_20161107周一的更多相关文章

  1. KETTLE监控

    kettle单实例环境下自身没有监控工具,但在集群下自带了监控工具. 一.集群自带的监控 kettle自带的集群监控工具可以监控转换的执行情况. 配置好集群后,打开浏览器:输入http://local ...

  2. MySQL上周新增激活用户在上周下单情况_20161107周一

    上周新增激活用户在上周下单情况 1.上周激活用户明细 #上周激活用户明细 SELECT a.城市,a.用户ID,a.用户名称,b.用户地址,b.联系电话,a.订单日期,c.年周,c.上周一,a.订单I ...

  3. MVC4.0系统开发新手历程(四)数据列表查询

    任何系统都不可避免的就是数据的查询展示,我觉得这里最值得一说的就是分部视图以及数据分页了 首先添加控制器 在控制其上面的名字为Index的Action上面右击,添加视图即可添加对应的视图,分部视图呈现 ...

  4. Quartz任务调度(2)CronTrigger定制个性化调度方案

    Cron表达式 1. 时间字段与基本格式 Cron表达式有6或7个空格分割的时间字段组成: 位置 时间域名 允许值 允许的特殊字符 1 秒 0-59 ,-*/ 2 分支 0-59 ,-*?/ 3 小时 ...

  5. 技术杂记-改造具有监控功能的数据库连接池阿里Druid,支持simple-jndi,kettle

    kettle内置的jndi管理是simple-jndi,功能确实比较简单,我需要监控kettle性能,druid确实是很不错的选择,但没有提供对应的支持,我改进了druid源码,实现了simple-j ...

  6. 基于kettle的简单HTTP接口监控

        需求:监控系统中使用的所有http接口,要求简单,易用. 一般的思路也就是发送get/post请求,然后检查接口的响应结果. 如果写代码,要处理http请求,检查http响应,实现发邮件,写d ...

  7. kettle转换和作业插件开发及调试

    这是一篇几年前写下的文档,最近打算根据这篇文档重写一下kettle插件的教程.结果各种理由,一推再推.今天索性将这篇文档发布出来,分享给大家,例子等有空再补上.这是一篇基于kettle3.2基础上完成 ...

  8. kettle系列-1.kettle源码获取与运行

    第一次写博客,心里有点小激动,肯定有很多需要改进的地方,望海涵. kettle算是我相对较为深入研究过的开源软件了,也是我最喜欢的开源软件之一,它可以完成工作中很多体力劳动,在ETL数据抽取方面得到了 ...

  9. 【转】Kettle集群

    本文转自:http://blog.csdn.net/dqswuyundong/article/details/5952009 Kettle集群 Kettle是一款开源的ETL工具,以其高效和可扩展性而 ...

随机推荐

  1. ubuntu 下开源安装

    常用开源库安装: 0.安装g++: sudo apt-get install g++ 1.首先不可或缺的就是编译器与基本的函式库: sudo apt-get install build-essenti ...

  2. Msfvenom 学习笔记与总结

    平台:Android,可用Payload: android/meterpreter/reverse_http Run a meterpreter server on Android. Tunnel c ...

  3. Android TelephonyManager类的使用

    TelephonyManager类主要提供了一系列获取手机与通讯相关的状态和信息的get方法,包含手机用户的信息.手机SIM的状态.电信网络的状态等. TelephonyManager类的对象的获取: ...

  4. Linux进程间通信(IPC)编程实践(十二)Posix消息队列--基本API的使用

    posix消息队列与system v消息队列的区别: (1)对posix消息队列的读总是返回最高优先级的最早消息,对system v消息队列的读则能够返回随意指定优先级的消息. (2)当往一个空队列放 ...

  5. DataTable去除空行

    protected void removeEmpty(DataTable dt) { List<DataRow> removelist = new List<DataRow>( ...

  6. NorFlash linux分区分析

    一般情况下,与板卡相关的内容都在bsp中(即arch/arm/mach-xxx/board-xxx.c)中,但norflash的分区直接放在norflash驱动中.由于norflash应用基于mtd, ...

  7. 【WPF学习笔记】之如何通过后台C#代码添加(增/删/改按钮)实现对SQLServer数据库数据的更改

    首先,需要连接SQLServer数据库的服务器名称server.数据库名database.数据库用户名uid以及密码pwd,如下图: 然后需要以下数据库SQL代码段,还有一个myHelper.cs代码 ...

  8. JavaWeb学习总结第三篇--走进JSP页面元素

    JavaWeb学习(三)—走进JSP页面元素 JSP:Java Server Pages,译为Java服务器页面.其脚本采用Java语言,继承了Java所有优点.JSP元素可以分为指令元素.脚本元素和 ...

  9. Android之——卸载应用程序

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47357729 不多说,不废话,直接上代码,大家都懂得 //卸载应用程序 //參数为 ...

  10. python 基础 4.4 生成式 生成器 迭代器

    一.生成式和生成器   列表生成式是python受欢迎的语法之一,通过一句简洁的语法就可以对一组元素进行过滤,还可以对得到的元素进行转换处理.   #/usr/bin/python #coding=u ...