select  satisfy.STARTTIME,cc.C_CrmID,cc.C_Name ClientName,be.C_NAME,count(yskj.c_id) PhoneSum,sum(cast (satisfy.SATISFYCODE as int)) PointSum,
sum(case yskj.C_CallType when 1 then 1 else 0 end) AnswerSum,sum(case yskj.C_CallType when 1 then satisfy.SATISFYCODE else 0 end) AnswerPoint,
sum(case yskj.C_CallType when 2 then 1 else 0 end) DialSum,sum(case yskj.C_CallType when 2 then satisfy.SATISFYCODE else 0 end) DialPoint,
sum(case satisfy.SATISFYCODE when 1 then 1 else 0 end) SatisfySum,sum(case satisfy.SATISFYCODE when 2 then 1 else 0 end) CommonSum,
sum(case satisfy.SATISFYCODE when 3 then 1 else 0 end) NoSatisfySum,sum(case satisfy.SATISFYCODE when 0 then 1 else 0 end) NoEval
  from cti.dbo.CC_IVR_SATISFYINFO satisfy with(nolock)
left join cti.dbo.CTI_TBL_Contact_Base_YSKJ yskj with(nolock) on yskj.C_AgentID=satisfy.agentid and yskj.C_StartTime>=@begin and yskj.C_StartTime<=@end
and  satisfy.STARTTIME>=@begin and satisfy.STARTTIME<=dateadd(day,1,@end)
left join Base_Employee be with(nolock) on be.C_CODE=satisfy.agentid
left join CRM_Client cc with(nolock) on cc.C_CrmID=yskj.C_ClientID
group by satisfy.STARTTIME,cc.C_CrmID,cc.C_Name,be.C_NAME

用户子查询,用case的更多相关文章

  1. 高级子查询【weber出品必属精品】

    多列子查询 where条件中出现多列与子查询进行比较 多列子查询分为:成对比较和非成对比较 成对比较: SQL> select ename,sal,job from emp where (dep ...

  2. SQL夯实基础(四):子查询及sql优化案例

    首先我们先明确一下sql语句的执行顺序,如下有前至后执行: (1)from  (2) on   (3) join  (4) where  (5)group by  (6) avg,sum...  (7 ...

  3. 【MySQL】02_子查询与多表查询

    子查询 指一个查询语句嵌套在另一个查询语句内部的查询,这个特性从MySQL 4.1开始引入. SQL 中子查询的使用大大增强了 SELECT 查询的能力,因为很多时候查询需要从结果集中获取数据,或者 ...

  4. 第09章 MySQL子查询

    第09章 MySQL子查询 子查询指一个查询语句嵌套在另一个查询语句内部的查询,这个特性从MySQL 4.1开始引入. SQL 中子查询的使用大大增强了 SELECT 查询的能力,因为很多时候查询需要 ...

  5. 走向面试之数据库基础:二、SQL进阶之case、子查询、分页、join与视图

    一.CASE的两种用法 1.1 等值判断->相当于switch case (1)具体用法模板: CASE expression WHEN value1 THEN returnvalue1 WHE ...

  6. Oracle-3 - :超级适合初学者的入门级笔记--用户权限,set运算符,高级子查询

    上一篇的内容在这里第二篇内容, 用户权限:创建用户,创建角色,使用grant  和 revoke 语句赋予和回收权限,创建数据库联接 创建用户:create user xxx identified b ...

  7. 输出,变量的使用,子查询,逻辑语句,循环,case..when..then..end多分支语句,Exists(判断存在)

    --------------输出----------------print 'hello world'--以文本形式输出select 'hello world'--以网格形式输出,也可以设置成以文本形 ...

  8. oracle之子查询、创建用户、创建表、约束

      子查询                                    子查询可以分为单行子查询和多行子查询   单行子查询           [1] 将一个查询的结果作为另外一个查询的条 ...

  9. SQL Server -- 回忆笔记(四):case函数,索引,子查询,分页查询,视图,存储过程

    SQL Server知识点回忆篇(四):case函数,索引,子查询,分页查询,视图,存储过程 1. CASE函数(相当于C#中的Switch) then '未成年人' else '成年人' end f ...

随机推荐

  1. GO逆转字符串

    package main import "fmt" func main(){ str:="foobar" a:=[]rune(str) ,len(a)-;i&l ...

  2. tomcat文件夹与文件解析

    今天看到一篇不错的文章,如下: /bin:存放启动和关闭tomcat的脚本文件: /conf:存放tomcat的各种配置文件,比如:server.xml/ server/lib:存放tomcat服务器 ...

  3. Express4 Route笔记

    可以参考Express官网关于路由一节:http://expressjs.com/guide/routing.html 1:通过使用GET.POST方式定义主页路由,app.js: var expre ...

  4. BZOJ 2732 射箭

    http://www.lydsy.com/JudgeOnline/problem.php?id=2732 题意:给你n个靶子,让你求是否有一个经过原点的抛物线经过最多的前k个靶子,求出最大的k 思路: ...

  5. Python partial函数

    以前都是摘录的其他网友的博客,很少是自己写的,学习阶段,多多学习.今天开始自己写了,首先写一下刚刚遇到的partial函数. 1.partial函数主要是对参数的改变,假如一个函数有两个参数,而其中一 ...

  6. spoj1812-Longest Common Substring II(后缀自动机)

    Description A string is finite sequence of characters over a non-empty finite set Σ. In this problem ...

  7. C++ double类型转string类型后,怎么实现小数点后只显示一个数字

    C++ double类型转string类型后,怎么实现小数点后只显示一个数字 #include <iostream> #include <sstream> #include & ...

  8. 关于bootstrap--列表(ol、ul)

    1.list-unstyled : 在<ol>(有序列表)</ol><ul>(无序列表)</ul>中加入class="list-styled& ...

  9. [iOS] Create TableView & customize UITableViewCell

    1. First artical, notice the last thing - Connecting the DataSource and Delegate: http://www.appcoda ...

  10. ubuntu14.04 cocos2d-x-3.6 glfw编译出错解决方案

    lib/libcocos2d.a(CCGLViewImpl-desktop.cpp.o): In function `cocos2d::GLViewImpl::GLViewImpl()': /home ...