1

最右边的列是我要添加到报告中的内容。是否可以在不修改查询以使用 Unpivot 之类的东西的情况下做到这一点?

Step X      Step W      Step A     Step B     Step Y     Last Step
---------------------------------------------------------------------
1/21/2013   1/24/2013   1/3/2013   1/5/2013   1/7/2013   Step W

这是朝着正确方向迈出的一步,但它似乎只适用于 SSRS 2008: http: //www.bigator.com/2012/04/26/spothighlight-minimum-and-maximum-values-in-each-row -in-matrix-report-in-ssrs/

4

1 回答 1

2

您可以使用UNPIVOT函数和 aCROSS APPLY来获得:

;with cte as
(
  select col, value
  from yourtable
  unpivot
  (
    value
    for col in ([Step X], [Step W], [Step A], [Step B], [Step Y])
  ) unpiv
) 
select [Step X], 
  [Step W], 
  [Step A], 
  [Step B], 
  [Step Y],
  d.col LastStep
from yourtable
cross apply
(
  select c1.col
  from cte c1
  inner join
  (
    select max(value) MaxDate
    from cte
  ) c2
    on c1.value = c2.maxdate
) d

请参阅带有演示的 SQL Fiddle

于 2013-02-15T20:42:33.407 回答