SQL Server 2008-数据透视
需要帮助旋转一些数据吗SQL Server 2008-数据透视,sql,sql-server,Sql,Sql Server,需要帮助旋转一些数据吗 SELECT [contact_list_name] as 'Table' ,[ov_number_dialed] as 'Number Dialed' ,convert(date, [time_of_contact], 101) as 'Date' ,convert(time, dateadd(hour, -7,[time_of_contact]), 108) as 'Time' ,agent_full_name as 'Agent'
SELECT
[contact_list_name] as 'Table'
,[ov_number_dialed] as 'Number Dialed'
,convert(date, [time_of_contact], 101) as 'Date'
,convert(time, dateadd(hour, -7,[time_of_contact]), 108) as 'Time'
,agent_full_name as 'Agent'
,[response_status] as 'Disp'
FROM
[meldb].[dbo].[cl_contact_event]
这给了我这样的结果:
我想突出显示或显示结果,以便disp像
有什么想法吗 根据您的评论,一个简单的支点方法是将
max
与case
一起使用:
select
[contact_list_name] as 'Table'
, [ov_number_dialed] as 'Number Dialed'
, convert(date, [time_of_contact], 101) as 'Date'
, convert(time, dateadd(hour, -7,[time_of_contact]), 108) as 'Time'
, agent_full_name as 'Agent'
, max(case when [response_status] = 'DAM' then response_status end) as 'Disp1_DAM'
, max(case when [response_status] = 'DNA' then response_status end) as 'Disp2_DNA'
...
FROM [meldb].[dbo].[cl_contact_event]
GROUP BY
[contact_list_name]
, [ov_number_dialed]
, convert(date, [time_of_contact], 101)
, convert(time, dateadd(hour, -7,[time_of_contact]), 108)
, agent_full_name
您是否有最大数量的
disp
记录?如果是这样,您可以将pivot
或max
与case
一起使用。如果没有,则需要使用动态sql
。有很多关于它的帖子。我最多会有6条disp记录,我想我不需要更多了。我只是不能让pivot正常工作,或者根本就不能……你知道这6个值是什么吗——总是DAM
,CBS
,等等?如果这些是动态的,那么您必须使用动态sql
。DAM、DNA、NML、NN、NR、NAN我如何根据何时使用DISP更改订单?我感谢你的帮助