2

我得到了这个代码,它目前根据给定的标准对呼叫中心进行排名。我的任务是将此排名从基于中心更改为副总监(AKA AD、经理、BottomUpLevel02)。

问题是,我没有很多实际创建表格的经验。我通常会操纵视图,所以我确信这里有一些我严重缺乏的语法规则。

这是代码:

SET NOCOUNT ON 
DECLARE @StartDate SMALLDATETIME, 
        @EndDate SMALLDATETIME 
SET @StartDate = '2012/07/01' 
SET @EndDate = '2012/07/31' 

IF OBJECT_ID('tempdb..#ACSResults') IS NOT NULL DROP TABLE #ACSResults 

CREATE TABLE #ACSResults (AreaID VARCHAR(4), Location VARCHAR(50), 
                          MonthName VARCHAR(6),
                          RepResolve FLOAT, ERP FLOAT)
INSERT INTO #ACSResults 
SELECT a.area, a.location,
a.monthname,
CASE WHEN SUM(CASE WHEN a.RepResolve IN ('1','0') 
                        THEN 1 
                   ELSE 0 END) = 0 
          THEN NULL  
          ELSE CAST(SUM(CASE WHEN a.RepResolve = '1' 
                                  THEN 1 
                             ELSE 0 END)AS FLOAT) / CAST(SUM(CASE WHEN a.RepResolve IN ('1','0') 
                                                                       THEN 1 
                                                                  ELSE 0 END) AS FLOAT) END AS REPRESOLVE,
CASE WHEN SUM(CASE WHEN a.ERP IN ('0','1','2','3','4','5','6','7','8', '9', '10') 
                        THEN 1 
                   ELSE 0 END) = 0 
          THEN NULL 
     ELSE (CAST(SUM(CASE WHEN a.ERP IN ('8', '9', '10') 
                              THEN 1 
                         ELSE 0 END) AS FLOAT) / CAST(SUM(CASE WHEN a.ERP in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10') 
                                                                    THEN 1 
                                                               ELSE 0 END) AS FLOAT))END AS ERP

FROM (SELECT CASE WHEN vl.virtuallocationtypeid =13 
                       THEN 'PP'
                  WHEN eh.PeopleSoftDepartmentID IN ('2922', '9050', '9136', '9130','9134','9135', '9137', '9060') 
                       THEN 'FS'
                  WHEN eh.PeopleSoftDepartmentID ='2390' 
                       THEN 'CMO'
                  WHEN eh.virtuallocationtypeid = 3 
                  OR eh.peoplesoftDepartmentid IN ('9165', '9166','9157','9167','<<OSVBSC>>') 
                       THEN 'BSC'
                  WHEN (eh.virtuallocationid IN ('111', '113', '114', '115', '116', '118', '119', '120', '122', '123') 
                        AND acs.OfferDate  < '04/01/2011') 
                  OR (eh.virtuallocationid IN ('116','120','123') 
                      AND acs.OfferDate  >= '04/01/2011') 
                        THEN 'SPC2'
                  WHEN (eh.virtuallocationid IN ('112', '121', '110') 
                        AND acs.OfferDate  >= '07/01/2011') 
                       THEN 'SPC2'
                  WHEN (eh.virtuallocationid IN ('99') 
                        AND acs.OfferDate < '07/01/2011') 
                        AND eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>') 
                       THEN 'SPC2'
                  WHEN eh.EmployeeTypeID = 'V' 
                       THEN 'SPC'
                  WHEN vl.virtuallocationtypeid =14 
                       THEN 'SPC2'
                  WHEN (eh.virtuallocationID IS NULL 
                        AND eh.AreaId IS NULL) 
                       THEN eh.PeopleSoftAreaID 
                  WHEN eh.virtuallocationID IS NULL 
                       THEN eh.AreaID 
                       ELSE vl.AreaId END AS Area,
             CASE WHEN eh.VirtualLocationID = 102 
                       THEN 'HQ Quality - GSC'
                  WHEN eh.peoplesoftDepartmentid IN ('9165', '9166','9167') 
                       THEN 'GSC'
                  WHEN eh.peoplesoftdepartmentid ='<<OSVAOL>>' 
                  AND eh.virtuallocationid =64  
                       THEN 'ALORICA AOL'
                  WHEN (eh.virtuallocationid IN ('99', '148')
                        AND eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>')) 
                       THEN 'Wichita Falls (WDS) - Tech'
                  WHEN eh.virtuallocationID IS NULL 
                  OR vl.VirtualLocationTypeID = 4 
                       THEN 'Others'
                  ELSE vl.VirtualLocationDescription END AS Location,
             CASE WHEN eh.PeopleSoftDepartmentID IN ( '9180', '<<WEBILING>>','<<OSVSPN>>') 
                       THEN 'Bilingual'
                  WHEN eh.PeopleSoftDepartmentID IN ( '9150', '9440', '9370', '9260', '9330', '9460','9155','9215','9157','9175','<<OSVBSC>>') 
                       THEN 'BSC'
                  WHEN eh.PeopleSoftDepartmentID IN ( '9395', '9010', '9341', '9340', '9450', '9131', '9025', '10014901', '<<SO_WEVIS>>', '<<WE_MWVIS>>', '<<WEVIS>>', '<<NEVIS>>', '<<OSCCALTEL>>', '<<SOVIS>>', '<<NE_MWVIS>>', '<<MWVIS>>', '<<OSVCS>>') 
                       THEN 'Care'
                  WHEN eh.PeopleSoftDepartmentID IN ('9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>' ) 
                       THEN 'Tech'
                  WHEN eh.PeopleSoftDepartmentID IN ('<<AOL_WEVIS>>', '<<OSVAOL>>') 
                       THEN 'AOL'
                  WHEN eh.peoplesoftdepartmentid IN ('<<OSVCS_TCS>>', '<<OSVOB_TCS>>')
                       THEN 'New Hire Transition'
                  WHEN eh.PeopleSoftDepartmentID = '9390' 
                       THEN 'EPP'
                  WHEN eh.PeopleSoftDepartmentID = '9120' 
                       THEN 'ERT'
                  WHEN eh.PeopleSoftDepartmentID = '9190' 
                       THEN 'IRT'
                  WHEN eh.PeopleSoftDepartmentID = '9085' 
                       THEN 'Bilingual Tech'
                  WHEN eh.PeopleSoftDepartmentID IN ('9490', '<<LNP>>','<<OSVLNP>>')
                       THEN 'LNP'
                  WHEN eh.PeopleSoftDepartmentID = '9070' 
                       THEN 'Retention'
                  WHEN eh.PeopleSoftDepartmentID = '9115' 
                       THEN 'GLOBAL'
                  WHEN eh.PeopleSoftDepartmentID IN ('<<ONEBILL>>', '<<OSVOB>>') 
                       THEN 'Onebill'
                  WHEN eh.peoplesoftdepartmentid = '<<PPCARE>>' 
                       THEN 'Prepaid Care'
                  WHEN eh.peoplesoftdepartmentid = '<<PPTECH>>' 
                       THEN 'Prepaid Tech'
                  ELSE 'Other' END AS DeptGroup,
             psd.PeopleSoftDepartmentDescription AS Dept, 
             acs.IVRCallID, 
             acs.OfferDate, 
             acs.EmployeeID,
             acs.ACSSUserID, 
             Cast(acs.DidRepResolve as Float) As RepResolve,
             acs.Question1 AS FCR, 
             acs.Question2 AS ERP, 
             acs.Question3 AS NPS, 
             acs.ACSSCallID,
             month (acs.Offerdate) AS MonthName

      FROM dbCustomerSurvey.Detail.vwAfterCallSurvey acs 
      LEFT JOIN dbEmployee.Summary.vwEmployeeHistory eh 
                ON acs.EmployeeID = eh.EmployeeID 
                AND acs.OfferDate BETWEEN eh.StartDate 
                AND eh.EndDate 
      LEFT JOIN dbEmployee.Config.vwName Rep 
                ON eh.EmployeeID = Rep.EmployeeID 
      LEFT JOIN dbEmployee.Config.vwName Sup 
                ON eh.BottomUp01ID = Sup.EmployeeID
      LEFT JOIN dbEmployee.Config.vwName Mgr 
                ON eh.BottomUp02ID = Mgr.EmployeeID
      LEFT JOIN dbEmployee.Config.vwName Dir 
                ON eh.BottomUp03ID = Dir.EmployeeID
      LEFT JOIN dbEmployee.Config.vwVirtualLocation vl 
                ON eh.VirtualLocationID = vl.VirtualLocationID 
      LEFT JOIN dbEmployee.Config.vwDepartment d 
                ON eh.DepartmentID = d.DepartmentID 
      LEFT JOIN dbEmployee.Config.vwPeopleSoftDepartment psd
                ON eh.PeopleSoftDepartmentID = psd.PeopleSoftDepartmentID
      WHERE acs.CurrentStatus IN ('Completed', 'COMP') 
            AND acs.surveytype IN ('ACS_FCR_Rep_Perform', 'ACS_FCR_Rep_Perform-prepaid', 'ACS_Rep_Perform_BSC2', 'ACS_Rep_Perform_Gov') 
            AND acs.OfferDate BETWEEN @StartDate AND @EndDate) a 

WHERE a.Area IN ('WE', 'mw','ne','so') 
      AND a.Location NOT IN ('West Area Staff - CS', 'Northeast Area Staff - CS', 'Midwest Area Staff - CS', 'Others', 'West Area Finance - CS', 'Midwest Area Marketing, Sales, & Training', 'South Area Staff - CS', 'Midwest Area Finance - CS', 'Bellevue - CS')
      AND a.deptgroup in ('aol','bilingual','Bilingual Tech','care','global','lnp', 'onebill','other','retention','tech', 'new hire transition') 

GROUP BY a.area, a.location, a.monthname

-- 重复表

IF OBJECT_ID('tempdb..#HRRep')  IS NOT NULL DROP TABLE #HRRep 

CREATE TABLE #HRRep (AreaID VARCHAR(4), Location VARCHAR(50), 
                     MonthName VARCHAR(6), 
                     HourRepeatPercent FLOAT)
INSERT INTO #HRRep (AreaID, Location, MonthName, HourRepeatPercent) 
SELECT eh.AreaID, vl.VirtualLocationDescription, 
       MONTH (acs.statdate) AS MonthName,

       CAST(SUM(acs.Repeats2Hr)as FLOAT) / NULLIF(SUM(acs.Calls2Hr), 0) as 'HourRepeatPercent'

FROM dbReportSummary.ReportSummary.vwRepeatCalls2Hr acs WITH (NOLOCK)
LEFT JOIN dbEmployee.Summary.vwEmployeeHistory eh WITH (NoLOCK) 
          ON acs.EmployeeID = eh.EmployeeID 
          AND acs.StatDate BETWEEN eh.StartDate AND eh.EndDate 
LEFT JOIN dbEmployee.Config.vwVirtualLocation vl 
          ON eh.VirtualLocationID = vl.VirtualLocationID 
LEFT JOIN dbEmployee.Config.vwDepartment d 
          ON eh.DepartmentID = d.DepartmentID 
LEFT JOIN dbEmployee.Config.vwPeopleSoftDepartment psd 
          ON eh.PeopleSoftDepartmentID = psd.PeopleSoftDepartmentID

WHERE acs.StatDate BETWEEN @StartDate AND @EndDate
      AND eh.PeopleSoftDepartmentID IN ('9180', '<<WEBILING>>','<<OSVSPN>>', '9150', '9440', '9370', '9260', '9330', '9460','9155','9215','9157','9175','<<OSVBSC>>', '9395', '9010', '9341', '9340', '9450', '9131', '9025', '10014901', '<<SO_WEVIS>>', '<<WE_MWVIS>>', '<<WEVIS>>', '<<NEVIS>>', '<<OSCCALTEL>>', '<<SOVIS>>', '<<NE_MWVIS>>', '<<MWVIS>>', '<<OSVCS>>', '9030', '9080', '9355', '9040', '<<OSCCALTECH>>', '<<WDTSMO>>', '9195','<<OSVTS>>', '<<AOL_WEVIS>>', '<<OSVAOL>>', '<<OSVCS_TCS>>', '<<OSVOB_TCS>>'    , '9390', '9120', '9190', '9085', '9490', '<<LNP>>', '<<OSVLNP>>', '9070', '9115', '<<ONEBILL>>', '<<OSVOB>>', '<<PPCARE>>', '<<PPTECH>>')
      AND eh.AreaID IN ('MW', 'NE', 'SO', 'WE')
      AND vl.VirtualLocationDescription NOT IN ('West Area Staff - CS', 'Northeast Area Staff - CS', 'Midwest Area Staff - CS', 'Others', 'West Area Finance - CS')
AND eh.Titleid IN ('1','2','3','509') 

GROUPBY  eh.AreaID, vl.VirtualLocationDescription, MONTH (acs.statdate)

-- (?) --

SELECT a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent,
       a.RepeatRank, (a.RRRank + a.ERPRank+a.RepeatRank) as 'Total Rank Points', 
       RANK() OVER(ORDER BY (a.RRRank + a.ERPRank+a.RepeatRank) ASC, a.RepResolve DESC) AS 'Overall Rank'
FROM (SELECT a.Location, a.RepResolve, 
             RANK() OVER(ORDER BY a.RepResolve DESC) AS RRRank, a.ERP, 
             RANK() OVER(ORDER BY a.ERP DESC) AS ERPRank, b.HourRepeatPercent, 
             RANK() OVER(ORDER BY b.HourRepeatPercent ASC) AS RepeatRank
      FROM #ACSResults AS A
      LEFT JOIN #HRRep AS B 
                ON a.areaid = b.areaid 
                AND a.monthname = b.monthname 
                AND a.location = b.location) a
GROUP BY a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent,
         a.RepeatRank, (a.RRRank + a.ERPRank + a.RepeatRank)

当我尝试将 AD 添加到组合中时,我不断收到有关 select 子句与 insert 子句不匹配的错误。任何人都可以指出需要修改以包含 AD 的区域吗?

编辑:我能够成功添加一个广告列!新问题:结果有点偏离。在根据位置对结果进行排名之前,每个不同的位置都会根据总点数分配一个排名。它很干净,数字加起来了。现在有重复的AD,排名倒退(总排名积分最少的被列为第一名)。

我只是将 AD 列添加到 INSERT 语句和 select 语句中。谁能告诉我,除了在查询的适当位置添加 AD 列之外,我是否应该修改查询的任何操作或功能以反映给定日期范围的真实排名?请随时要求对此的任何部分进行澄清。提前感谢您提供的任何帮助。

4

3 回答 3

1

让发条缪斯的想法更加生动。如果您被允许创建表,请从(用您的数据库实际拥有的任何内容替换 nvarchars)开始

Create Table dbo.DepartmentGroupLookup (
  PeopleSoftDepartmentID nvarchar(30) Primary Key Not Null,
  DeptGroup nvarchar(30) not null
)

Insert Into dbo.DepartmentGroupLookup (PeopleSoftDepartmentID, DeptGroup) Values
  ('9180', 'Bilingual'), ('<<WEBILING>>', 'Bilingual'), ..., ('9150', 'BSC'), ... etc

Create Function dbo.LookupLocation(
  @VirtualLocationID as int, 
  @VirtualLocationDescription nvarchar(30),
  @VirtualLocationTypeID int,
  @PeopleSoftDepartmentID nvarchar(30)
) Returns nvarchar(30) As
Begin
  Return Case 
    When @VirtualLocationID = 102 Then 'HQ Quality - GSC'
    When @PeopleSoftDepartmentID In ('9165', '9166','9167') Then 'GSC'
    When @PeopleSoftDepartmentID ='<<OSVAOL>>' And @VirtualLocationID = 64 Then 'ALORICA AOL'
    When @VirtualLocationID In ('99', '148') And 
      @PeopleSoftDepartmentID In (
        '9030', '9080', '9355', '9040', '<<OSCCALTECH>>', 
        '<<WDTSMO>>', '9195','<<OSVTS>>'
      ) Then 'Wichita Falls (WDS) - Tech'
    When @VirtualLocationID Is Null Or @VirtualLocationTypeID = 4 Then 'Others'
    Else @VirtualLocationDescription 
    End
 End

对区域查找做类似的事情,现在你的第一个内部查询变成了

Select
  dbo.LookupArea(eh.virtuallocationID, v1.virtuallocationtypeid, vl.AreaId,  eh.PeopleSoftAreaID,
      eh.PeopleSoftDepartmentID, acs.OfferDate, eh.EmployeeTypeID) As Area, -- There may be other dependencies
  dbo.LookupLocation(eh.VirtualLocationID, vl.VirtualLocationDescription,
      vl.VirtualLocationTypeID, eh.peoplesoftDepartmentid) As Location,
  IsNull(dgl.DeptGroup, 'Other') AS DeptGroup,
  psd.PeopleSoftDepartmentDescription AS Dept, 
  acs.IVRCallID, 
  acs.OfferDate, 
  acs.EmployeeID,
  acs.ACSSUserID, 
  Cast(acs.DidRepResolve as Float) As RepResolve,
  acs.Question1 AS FCR, 
  acs.Question2 AS ERP, 
  acs.Question3 AS NPS, 
  acs.ACSSCallID,
  Month(acs.Offerdate) AS MonthName
From
  dbCustomerSurvey.Detail.vwAfterCallSurvey acs 
    Left Outer Join
  dbEmployee.Summary.vwEmployeeHistory eh 
    On acs.EmployeeID = eh.EmployeeID And acs.OfferDate Between eh.StartDate And eh.EndDate 
    Left Outer Join
  dbEmployee.Config.vwName Rep 
    On eh.EmployeeID = Rep.EmployeeID 
    Left Outer Join 
  dbEmployee.Config.vwName Sup 
    On eh.BottomUp01ID = Sup.EmployeeID
    Left Outer Join
  dbEmployee.Config.vwName Mgr 
    On eh.BottomUp02ID = Mgr.EmployeeID
    Left Outer Join
  dbEmployee.Config.vwName Dir 
    On eh.BottomUp03ID = Dir.EmployeeID
    Left Outer Join
  dbEmployee.Config.vwVirtualLocation vl 
    On eh.VirtualLocationID = vl.VirtualLocationID 
    Left Outer Join
  dbEmployee.Config.vwDepartment d 
    On eh.DepartmentID = d.DepartmentID 
    Left Outer Join
  dbEmployee.Config.vwPeopleSoftDepartment psd
    On eh.PeopleSoftDepartmentID = psd.PeopleSoftDepartmentID
    Left Outer Join
  dbo.DepartmentGroupLookup dgl
    On eh.PeopleSoftDepartmentID = dgl.PeopleSoftDepartmentID
Where 
 acs.CurrentStatus In ('Completed', 'COMP') And
 acs.surveytype In (
     'ACS_FCR_Rep_Perform', 'ACS_FCR_Rep_Perform-prepaid',
     'ACS_Rep_Perform_BSC2', 'ACS_Rep_Perform_Gov'
 ) And
 acs.OfferDate Between @StartDate And @EndDate

目标是以这种方式继续简化(或至少将东西移出视线),直到可以理解发生了什么。

于 2012-11-15T20:34:28.833 回答
0

劳伦斯说得对。

当 SQL 代码开始看起来像这样时,缩进是我(和每个人)的朋友。如果派生集是缩进的,则更容易看到其定义的开始和结束位置:

SELECT some columns 
FROM
     (lots of hideous code) SetA
WHERE
    Things AND
    More Things

我已经从你不幸处理的代码片段中剪掉了大部分的丑陋之处:

CREATE TABLE #ACSResults (AreaID VARCHAR(4), Location VARCHAR(50),MonthName VARCHAR(6), RepResolve FLOAT, ERP FLOAT)
INSERT INTO #ACSResults 
  SELECT 
-- ColListStart
a.area,
a.location,
a.monthname,

 CASE WHEN SUM(CASE WHEN a.RepResolve IN ('1','0') THEN 1 ELSE 0 END) = 0 THEN NULL  ELSE CAST(SUM(CASE WHEN a.RepResolve = '1' THEN 1 ELSE 0 END)AS FLOAT) / CAST(SUM(CASE WHEN a.RepResolve IN ('1','0') THEN 1 ELSE 0 END) AS FLOAT) END AS REPRESOLVE,
CASE WHEN SUM(CASE WHEN a.ERP IN ('0','1','2','3','4','5','6','7','8', '9', '10') THEN 1 ELSE 0 END) = 0 THEN NULL ELSE (CAST(SUM(CASE WHEN a.ERP IN ('8', '9', '10') THEN 1 ELSE 0 END) AS FLOAT) / CAST(SUM(CASE WHEN a.ERP in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10') THEN 1 ELSE 0 END) AS FLOAT))END AS ERP
-- ColListEnd
FROM
    (/*Eurgh!  Hideous legacy code that makes my eyes bleed just glancing at it*/) a 

Where  a.Area IN ('WE', 'mw','ne','so') 
and a.Location not in ('West Area Staff - CS', 'Northeast Area Staff - CS', 'Midwest Area Staff - CS', 'Others', 'West Area Finance - CS', 'Midwest Area Marketing, Sales, & Training', 'South Area Staff - CS', 'Midwest Area Finance - CS', 'Bellevue - CS')
and a.deptgroup in ('aol','bilingual','Bilingual Tech','care','global','lnp', 'onebill','other','retention','tech', 'new hire transition') 

group by 
a.area,
a.location,
a.monthname

--------------------------------------------------------------------------------REPEAT TABLE------------------------------------------------------------------------------------------------------
 IF OBJECT_ID('tempdb..#HRRep') 
IS NOT NULL DROP TABLE #HRRep 
CREATE TABLE #HRRep (AreaID VARCHAR(4), Location VARCHAR(50),MonthName VARCHAR(6), HourRepeatPercent FLOAT)
INSERT INTO #HRRep (AreaID, Location, MonthName, HourRepeatPercent) 
  Select
  -- ColList Start
  eh.AreaID, vl.VirtualLocationDescription, Month (acs.statdate) AS MonthName,

Cast(Sum(acs.Repeats2Hr)as float) /nullif(Sum(acs.Calls2Hr), 0) as 'HourRepeatPercent'
    -- COlListEnd
From 
    /* More hideous legacy code */

如果您只是确保 SELECT 中的列与 INSERT 引用的表中的列匹配(我的评论 -ColListStart 和 -ColListEnd 定义了这个区域),那么“INSERT 和 SELECT 中的列必须匹配”错误将会消失。因此,您将额外的列添加到每个 CREATE TABLE,然后添加它(也许,最初,就像文字

'AnAreaDirector' AS AreaDirector

) 到 SELECT 语句,当然按顺序放在正确的位置。您还将在每个 SELECT 的末尾(即在其他所有内容之后)添加一个 GROUP BY AreaDirector。

然后真正的乐趣开始了,这是挖掘 () 中的内容(我已经剪掉了),并弄清楚您是否可以从其中引用的表中获取 AD 列,或者您是否需要加入另一张桌子。

于 2012-11-15T18:53:51.720 回答
0

编辑:我能够成功添加一个广告列!新问题:结果有点偏离。在根据位置对结果进行排名之前,每个不同的位置都会根据总点数分配一个排名。它很干净,数字加起来了。现在有重复的AD,排名倒退(总排名积分最少的被列为第一名)。

我只是将 AD 列添加到 INSERT 语句和 select 语句中。谁能告诉我,除了在查询的适当位置添加 AD 列之外,我是否应该修改查询的任何操作或功能以反映给定日期范围的真实排名?请随时要求对此的任何部分进行澄清。提前感谢您提供的任何帮助。

您的两个临时表(#ACS 和##HRRep)中都需要 AD 列,并且每个临时表(即 INSERT INTO .... SELECT FROM)的填充应该在 GROUP BY 中有 AD 列。然后,您的最终 SELECT 将需要连接 AD 列上的两个表以及连接表达式中已经存在的其他列。

我怀疑您在最终 SELECT 中不需要 GROUP BY,因为(我认为)这两个表已经具有按 areaid、location 等聚合的结果,并且 RANK() 是单行函数而不是像这样的聚合和:

LEFT JOIN #HRRep AS B 
                ON a.areaid = b.areaid 
                AND a.monthname = b.monthname 
                AND a.location = b.location) a
/* Probably don't need this bit
GROUP BY a.Location, a.RepResolve, a.RRRank, a.ERP, a.ERPRank,a.HourRepeatPercent,
         a.RepeatRank, (a.RRRank + a.ERPRank + a.RepeatRank)
But this bit: */
ORDER BY (a.RRRank+a.EPRank+a.RepeatRank) DESC

Laurence 建议创建一个映射表(他敢于深入研究第一组中的“丑陋”),因为它将“丑陋”隔离在一个地方。

于 2012-11-16T10:16:50.917 回答