0

我有以下数据:

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

在 SSRS 条形图中,名称将是 X 轴,值将是 Y 轴,类型将是系列。

我需要的是条形图将按每周值降序排序,所以预期的顺序应该是:

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

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

4

1 回答 1

0

您可以使用基于for类型ROW_NUMBER()为每个生成序列号,这将成为记录如何排序的基础。NameValueWeekly

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  ║
╚══════╩═══════╩════════╝
于 2013-06-26T05:21:43.737 回答