我被要求创建一个按年份分组的收入最多的特许经营列表,但是 order by 子句需要根据日期范围按收入最多的特许经营商进行排序。我可以按单笔金额(收入)罚款,但我如何按收入对特许经营分组进行排序?
group by
vFranMasterNumRollup.MasterFranNumber,
REPLACE(vFranMasterNumRollup.FranchiseName, ',', '') ,
YEAR(vremittheaderdetailandfran.remd_ServiceDate)
order by
sum(vremittheaderdetailandfran.remd_LaborRevenue) desc,
REPLACE(vFranMasterNumRollup.FranchiseName, ',', '')
你在这里看到我试图在排序中添加另一列,但我想将最高的特许经营组按降序排列
如果您需要更多代码,请告诉我
这是更多代码:
SELECT vFranMasterNumRollup.MasterFranNumber, REPLACE(vFranMasterNumRollup.FranchiseName, ',', '') AS FranchiseName,
sum(vremittheaderdetailandfran.remd_LaborRevenue),YEAR(vremittheaderdetailandfran.remd_ServiceDate)
FROM vremittheaderdetailandfran INNER JOIN
vFranMasterNumRollup ON vremittheaderdetailandfran.remh_FranchiseNumber = vFranMasterNumRollup.fran_FranchiseID
WHERE (vremittheaderdetailandfran.remd_ServiceDate BETWEEN @startdate and @enddate AND (vFranMasterNumRollup.fran_Status = N'ACTIVE') OR
(vremittheaderdetailandfran.remd_ServiceDate BETWEEN @startdate and @enddate))
group by vFranMasterNumRollup.MasterFranNumber,
REPLACE(vFranMasterNumRollup.FranchiseName, ',', '') , YEAR(vremittheaderdetailandfran.remd_ServiceDate)
order by sum(vremittheaderdetailandfran.remd_LaborRevenue) desc,REPLACE(vFranMasterNumRollup.FranchiseName, ',', '')