如何转动数据

时间:2015-04-01 15:23:46

标签: sql-server-2012

我想在以下查询中使用pivot函数来显示  左侧的DateAdded,AccountName,Campaign,CampaignGroup以及顶部的值总和将在顶部汇总

 SELECT CONVERT(varchar(10) , ct.dtAdded , 120)DateAdded
 , UPPER(szAccountName)Dealer
 , UPPER(c.szCampaign)Campaign
 , UPPER(cg.szCampaignGroup)CampaignGroup
 , CASE
   WHEN d.dialid IS NOT NULL
       THEN 1
       ELSE 0
   END NamesReceived
 , Attempts CallAttempts
 , CASE
   WHEN CallFlag = 1 AND Attempts < c.nMaxAttempts AND d.AgentId != -1
       THEN 1
       ELSE 0
   END EligibleRemaining
 , CASE
   WHEN szFaxType LIKE '%Appointment%'
       THEN 1
       ELSE 0
   END ApptFaxes
 , CASE
   WHEN szFaxType LIKE '%Hot%'
       THEN 1
       ELSE 0
   END HotFaxes
 , CASE
   WHEN szFaxType LIKE '%Service Opportunity%'
       THEN 1
       ELSE 0
   END ServiceOpFaxes
 , CASE
   WHEN szFaxType LIKE '%Basic%'
       THEN 1
       ELSE 0
   END BasicFaxes
 , CASE
   WHEN szQ25 IN('Now' , '30 Days' , '90 Days')
       THEN 1
       ELSE 0
   END InTheMarket
 , CASE
   WHEN CRC IN(
               SELECT szCRC COLLATE SQL_Latin1_General_CP1_CI_AS
                 FROM dbCallCenter..tblCallDispositionMap
                 WHERE bSurveyRecord = 1)
       THEN 1
       ELSE 0
   END CompletedSurveys
 , CASE
   WHEN CRC IN(
               SELECT szCRC COLLATE SQL_Latin1_General_CP1_CI_AS
                 FROM dbCallCenter..tblCallDispositionMap
                 WHERE bBadRecord = 1)
       THEN 1
       ELSE 0
   END BadRecords
 , CASE
   WHEN CRC IN(
               SELECT szCRC COLLATE SQL_Latin1_General_CP1_CI_AS
                 FROM dbCallCenter..tblCallDispositionMap
                 WHERE bContactRecord = 1)
       THEN 1
       ELSE 0
   END Contacts
 , CASE
   WHEN CRC IN(
               SELECT szCRC COLLATE SQL_Latin1_General_CP1_CI_AS
                 FROM dbCallCenter..tblCallDispositionMap
                 WHERE bPitchRecord = 1)
       THEN 1
       ELSE 0
   END Pitches
 , CASE
   WHEN CRC IN(
               SELECT szCRC COLLATE SQL_Latin1_General_CP1_CI_AS
                 FROM dbCallCenter..tblCallDispositionMap
                 WHERE bDNCRecord = 1)
       THEN 1
       ELSE 0
   END DNCRecords

FROM ...   WHERE ...

0 个答案:

没有答案