我正在运行迷你报告,SSRS中的图表对我来说只是一种痛苦。我试图从今天开始运行1年的迷你线 - 查询按月对数据进行分组,但我希望它按最新日期降序排序 - 所以它会显示1-2014,12 / 2013 ..然后返回
SELECT DATEPART(month, Orders.OrderDate) AS month, COUNT(Orders.OrderID) AS Count, SUM(Orders.GrossSubtotal) AS GrossRevenue, SUM(Orders.Subtotal) AS Revenue,
SUM(Orders.OrderCost) AS Cost, SUM(Orders.Subtotal) - SUM(Orders.OrderCost) AS Margin, SUM(Orders.Subtotal) / COUNT(Orders.OrderID) AS averageOrder
FROM Orders LEFT OUTER JOIN
Campaigns ON Orders.CampaignCode = Campaigns.CampaignCode CROSS JOIN
PK_StatsCurrentDatesCMP
WHERE (CONVERT(date, Orders.OrderDate, 103) BETWEEN PK_StatsCurrentDatesCMP.[1_YearRoll] AND PK_StatsCurrentDatesCMP.EndDate) AND
(Orders.SuppressFromStats = 0) AND (Orders.Void = 0) AND (Orders.WholesaleOrder = 0)
GROUP BY DATEPART(month, Orders.OrderDate)
ORDER BY month DESC
现在通过desc订购它只给了我12,11,10 ......
答案 0 :(得分:0)
我经历了所有麻烦来输入它,我想这篇文章解决了它 - 显而易见,我只需要 ORDER BY MAX(Orders.Orderdate) 希望这对某人有用