SSRS条形图按值排序

时间:2013-06-26 05:15:58

标签: sql-server reporting-services

我有以下数据:

-----------------
Name|Value|Type
-----------------
A   | 110 | Daily
-----------------
A   | 770 | Weekly
-----------------
B   | 150 | Daily
-----------------
B   | 700 | Weekly
-----------------
C   | 120 | Daily
-----------------
C   | 840 | Weekly

在SSRS条形图中,Name为X轴,Value为Y轴,Type为系列。

我需要的是条形图将按周价值递减排序,因此预期订单应为:

C Weekly
C Daily
A Weekly
A Daily
B Weekly
B Daily

怎么做?在查询或SSRS图表设置中?

1 个答案:

答案 0 :(得分:0)

您可以使用ROW_NUMBER()根据Name Value类型生成每个Weekly的序号,然后根据记录的基础排序

WITH records
AS
(
    SELECT  Name, 
            ROW_NUMBER() OVER (ORDER BY Value DESC) rn
    FROM    tableName
    WHERE   Type = 'Weekly'
)
SELECT  a.*
FROM    tableName a
        INNER JOIN records b
            ON a.Name = b.Name
ORDER   BY b.rn, a.Type DESC

输出

╔══════╦═══════╦════════╗
║ NAME ║ VALUE ║  TYPE  ║
╠══════╬═══════╬════════╣
║ C    ║   840 ║ Weekly ║
║ C    ║   120 ║ Daily  ║
║ A    ║   770 ║ Weekly ║
║ A    ║   110 ║ Daily  ║
║ B    ║   700 ║ Weekly ║
║ B    ║   150 ║ Daily  ║
╚══════╩═══════╩════════╝