select * from (
select isnull(c.type,'其他') type,d from
(
select ID,Record_code,code,day(thedate) d from search_record
where (Name!='' or Phone!='')--判断姓名或电话不为空
) zx
join customer c on zx.code=c.code
) a pivot (count(d) for d in([],[]))n alter proc tj_khlb_zxl_rq
@zxsj1 datetime ,--咨询时间开始,不能为空
@zxsj2 datetime,--咨询时间结束,不能为空
as
declare @sql Nvarchar(4000)
select @sql=isnull(@sql+',','')+'['+cast(d as varchar(2))+']'
from (select distinct day(thedate) d from search_record) n
set @sql='
select * from (
select isnull(c.type,''其他'') type,d from
(
select ID,Record_code,code,day(thedate) d from search_record
where (Name!='''' or Phone!='''')
and (thedate between @st and @en ) ) zx
join customer c on zx.code=c.code
) a pivot (count(d) for d in('+@sql+'))n '
exec sp_executesql @sql,N'@st datetime,@en datetime',@zxsj1,@zxsj2

行列转换 pivot的更多相关文章

  1. SQL Server中行列转换 Pivot UnPivot

    SQL Server中行列转换 Pivot UnPivot PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PI ...

  2. SQL Fundamentals: 子查询 || 行列转换(PIVOT,UNPIVOT,DECODE),设置数据层次(LEVEL...CONNECT BY)

    SQL Fundamentals || Oracle SQL语言 子查询(基础) 1.认识子查询 2.WHERE子句中使用子查询 3.在HAVING子句中使用子查询 4.在FROM子句中使用子查询 5 ...

  3. 【转】Spark实现行列转换pivot和unpivot

    背景 做过数据清洗ETL工作的都知道,行列转换是一个常见的数据整理需求.在不同的编程语言中有不同的实现方法,比如SQL中使用case+group,或者Power BI的M语言中用拖放组件实现.今天正好 ...

  4. 多列的行列转换(PIVOT,UNPIVOT)

    形式1 形式2 形式3 有时候可能会有这样的需求: 将一张表的所有列名转做为数据的一列数据,将一列数据作为整张表的列名 当列比较多时,只用PIVOT是解决不了的,经过研究,需要将UNPIVOT 和 P ...

  5. SQL中行列转换Pivot

    --建表 ),课程 ),分数 int) --插入数据 ) ) ) ) ) ) 1.静态行转列(确定有哪些列) select 姓名, end)语文, end)数学, end)物理 from tb gro ...

  6. 通过sql做数据透视表,数据库表行列转换(pivot和Unpivot用法)(一)

    在mssql中大家都知道可以使用pivot来统计数据,实现像excel的透视表功能 一.MSsqlserver中我们通常的用法 1.Sqlserver数据库测试 ---创建测试表 Create tab ...

  7. sql行列转换PIVOT与unPIVOT

    基本语法 select * from Mould pivot ( count(ID)for ProductTypeCode in ( [FC], [RCU], [RCD] )) as PVT; wit ...

  8. SQL Server中行列转换 Pivot UnPivot

    PIVOT用于将列值旋转为列名(即行转列),在SQLServer 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列)FOR 列 in (-) )AS P 完 ...

  9. SQLServer行列转换PIVOT函数中聚合函数的使用意义及选择

    例子:https://blog.csdn.net/wikey_zhang/article/details/76849826 DECLARE @limitDay INT;SET @limitDay = ...

随机推荐

  1. C语言中结构体 自引用 和 相互引用

    http://blog.163.com/modingfa_002/blog/static/11092546620133193264579 结构体的自引用(self reference),就是在结构体内 ...

  2. App Submission Issues

    查看原文: http://leancodingnow.com/app-submission-issues/ I bet many iOS developers are busy submitting ...

  3. 基于Andoird 4.2.2的同步框架源代码学习——同步发起端

    关键组件: ContentResolver ContentService SyncManager SyncManager.ActiveSyncContext SyncManager.SyncOpera ...

  4. Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分,贪心

    D. Gadgets for dollars and pounds 题目连接: http://www.codeforces.com/contest/609/problem/C Description ...

  5. (字符串的处理4.7.16)POJ 1159 Palindrome(让一个字符串变成回文串需要插入多少个字符...先逆序,在减去公共子序列的最大长度即可)

    /* * POJ_1159.cpp * * Created on: 2013年10月29日 * Author: Administrator */ #include <iostream> # ...

  6. Android Client and Jsp Server

    1. Interestfriend Server https://github.com/eltld/Interestfriend_server https://github.com/774663576 ...

  7. JAVA正则表达式语法大全

    [正则表达式]文本框输入内容控制 整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$ 只能输入数字:"^[0-9]*$". 只能输入n位的数字:"^\d{n ...

  8. 实例源码--Android图片滚动切换效果

    下载源码 技术要点:  1.图片滚动切换技术 2.详细的源码注释 ...... 详细介绍: 1.图片滚动切换技术 本套源码实现了类似于网站图片滚动推广效果,效果不错,很不错的参考源码 2.源码目录 运 ...

  9. Golang学习 - sync 包

    ------------------------------------------------------------ 临时对象池 Pool 用于存储临时对象,它将使用完毕的对象存入对象池中,在需要 ...

  10. Golang学习 - unicode/utf8 包

    ------------------------------------------------------------ // 编码所需的基本数字 const ( RuneError = '\uFFF ...